main() without console

Started by
8 comments, last by Wavarian 17 years, 11 months ago
Hello! I'm working on a game engine which handles the window creation. Until now, when using engine's library, I had to create a WinMain function. Now, I've changed this to main() so that it is simpler to the user. However, using main() creates a console window which cannot be destroyed using FreeConsole(). How can I get rid of this console window?
Advertisement
Quote:Original post by Trillian
Hello!

I'm working on a game engine which handles the window creation. Until now, when using engine's library, I had to create a WinMain function. Now, I've changed this to main() so that it is simpler to the user. However, using main() creates a console window which cannot be destroyed using FreeConsole().

How can I get rid of this console window?

If using Dev C++, you must go to Project -> Project Options, and on the first page/tab change from 'Win32 console' to 'Win32 GUI'.
I am 100% there is a better way to do it than this, but here is an idea.

int main (int argc, char** argv){    return 0;}int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int){    return main(__argc, __argv);}


That'll make WinMain call your main, and pass in the correct command line options into argc and argv. As I said, I am sure there is a better way, but I've never looked into it extensively.
Some IDEs (such as Dev-C++) allow you to explicitly state whether you want a console created automatically. I would imagine VS.NET has a similar option but I dont know where it is.
If you're using Visual Studio, I suppose you could change the linker options such as "/entry" and "/subsystem" in order to get rid of the console window.

For example,
#pragma comment(linker, "/entry:mainCRTStartup /subsystem:Windows")
Quote:Original post by JohnnyCasil
I am 100% there is a better way to do it than this, but here is an idea.

int main (int argc, char** argv){    return 0;}int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int){    return main(__argc, __argv);}


That'll make WinMain call your main, and pass in the correct command line options into argc and argv. As I said, I am sure there is a better way, but I've never looked into it extensively.


This is a good way to do it I think.

Simply hide the WinMain in the engine's belly and then use good old main as the implicit entry point.

"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
on XP you can ShowWindow(GetConsoleWindow(), SW_HIDE);.
Quote:Original post by yadango
on XP you can ShowWindow(GetConsoleWindow(), SW_HIDE);.

You'll still see the console for a split second though.
Does your ENGINE provide the main/WinMain function? If so, that's a pretty bad idea from a library usability standpoint. I don't see why your engine needs to know, or care, what the entry point was or how you need to do anything specific to "allow" your engine to be used with main() versus WinMain()... Can you explain further?
Quote:Original post by JohnnyCasil


I am rating you up!!

This topic is closed to new replies.

Advertisement