Reputation: 7401
I am creating a C++ program with Visual Studio 2010 that is supposed to run on the background of my machine.
Therefore when I start it, I shouldn't see the CMD screen while it is running. How can I do this? Do I have to use the Win32 API or a normal C++ program will suffice?
Please note that my program has no GUI at all.
Upvotes: 5
Views: 10437
Reputation: 26940
Use WinMain() :
#include <windows.h>
int WINAPI WinMain(HINSTANCE inst,HINSTANCE prev,LPSTR cmd,int show)
{
// program starts here
return 0;
}
// int main() <-- remove main()
Then ake sure your project settings are set so that you build a "Win32" program and not a "Console" program.
Edit: As @Sehe points out, winMain may not be necessary, although I am not quite sure where this option lies.
Upvotes: 14
Reputation: 5776
You can run as a Windows process (which doesn't attach to a console), but never create a window. the main difference is the signature of WinMain
, and the flags to the compiler.
Go to File -> New Project, select the standard Windows Application, then delete everything except WinMain
.
Upvotes: 0
Reputation: 34744
Simply make it a GUI application instead of a command line application. Right click the project -> Properties -> Configuration Properties -> Linker -> System -> SubSystem -> Windows (/SUBSYSTEM:WINDOWS).
Upvotes: 1
Reputation: 727047
In windows, Daemon programs are implemented as Services.
Upvotes: 2
Reputation: 101506
Very often a program running under Windows without a "face" (eg, with no user interface at all) is implemented as a Service.
Upvotes: 2