mackenir
mackenir

Reputation: 10969

How do I compile a C++ project with "DOS EXE" header flag == false?

I have a VS2010 C++ exe project that I want to compile so that the "DOS EXE" flag in the exe's header is set to false. This is (hopefully) to avoid the creation of a CONHOST.exe when the executable is run. The exe does not have a UI.

At the moment, I am calling ::FreeConsole on startup, to get rid of the CONHOST.exe process, but would prefer it if the CONHOST.exe were never created in the first place.

How can I do this?

Further to the selected answer, I 'fixed up' my code by adding a WinMain that calls through to the existing main, as follows:

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
  int argc;
  LPWSTR* argv = CommandLineToArgvW(pCmdLine, &argc);
  _tmain(argc, argv);
  LocalFree(argv);
}

Upvotes: 0

Views: 331

Answers (1)

imaximchuk
imaximchuk

Reputation: 748

You can try to change SubSystem value in linker options from CONSOLE to WINDOWS. This will prevent compiler from generating console-supporting code in the binary. Note that you will need to use WinMain() function instead of main()

Upvotes: 2

Related Questions