• Advertisement
Sign in to follow this  

main() without console

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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'.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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")

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
on XP you can ShowWindow(GetConsoleWindow(), SW_HIDE);.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by yadango
on XP you can ShowWindow(GetConsoleWindow(), SW_HIDE);.

You'll still see the console for a split second though.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement