# Windows console app

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, In windows, when your main function is a main() and not a WinMain() function, you get a console. I am using GLFW to manage my windows. So I don't need a WinMain function. Is there a way to make the console dissapear? ex. You double click the exe, you never see the console, and then the window GLFW creates appears. I want to make the console never appear. Is this possible? Thanks, Slaru

##### Share on other sites
Long answer: if you really really want to, I'm sure it's possible (through various API calls and events), but there's no easy way that I've ever seen

Console apps are meant to be just that: consoles. The fact that you can create windows is really just a side-effect of the fact that it's still a win32 app.

Most developers end up creating a stub WinMain that wraps whatever framework they're using. SDL, for example, provides a wrapper that creates the graphics context then calls your main() function so you can start the game.

##### Share on other sites
If I recall correctly, simply putting your main function in WinMain (and setting a windows, rather than console, subsystem) is all you need to do. WinMain does not automatically create a window.

##### Share on other sites
The reason I wanted to was so I can totally not rely on Windows, for easy cross-platform porting (GLFW is cross-platform). If it is very complicated, then I will just use windows and WinMain. But if there is a way not too complicated, then that would be nice.

##### Share on other sites
You will need to write some windows specific code. You can either achieve this as Sneftel suggested (/SUBSYTEM:Windows) and winmain, or you can just call
FreeConsole
Just use
#ifdef _WIN32
#endif
to ensure your windows specific code only compiles under windows

##### Share on other sites
You could try something like:

int main(void); #ifdef _WIN32 // If compiling for 32-bit Windowsint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){	return main(); // Note: If you have		       // int main(int argc, char **argv)		       // then you will have to parse lpCmdLine and fill in argc and argv yourself}#endifint main(void){...}

This ensures that, if compiling under Windows, WinMain() will be in the entry point and it will call main(), and if compiling under a different OS, main() will simply be the entry point.

##### Share on other sites
I never really saw the point of preferring WinMain over main. WinMain gets its parameters via GetModuleHandle(NULL) and GetCommandLine() anyway.

##### Share on other sites

I make GLUT apps all the time using main(). If you are using Visual Studio, add this line to your source:

#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

You could do it in the project properties, but this line is easier.

##### Share on other sites
Thanks mrbreakit. That worked perfectly! Exactly what I wanted.

Slaru

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 36
• ### Forum Statistics

• Total Topics
632634
• Total Posts
3007551
• ### Who's Online (See full list)

There are no registered users currently online

×