Sign in to follow this  

SDL console window

This topic is 3590 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

If I want to prevent the console window from opening when runnning a SDL app, can I just replace the
int main(int argc, char **argv)
with
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
and compile as a Win32 app or is there something more or else I need to do? Thanks.

Share this post


Link to post
Share on other sites
That will actually cause your program to fail to link. SDL uses a macro that redefines your main to a function that SDL calls from the actual main() or WinMain() function. Go to your linker settings and change the subsystem from console to windows.

Share this post


Link to post
Share on other sites
Quote:
Original post by AdamGL
Hmm, so how does the linker do this? I've done it myself, but can you tell me the specifics of how the program is defined to have a console window?

Well, any program can have a console window by calling AllocConsole(). However, what the linker does is sets the Subsystem word of the IMAGE_OPTIONAL_HEADER of the PE header for the executable to IMAGE_SUBSYSTEM_WINDOWS_CUI. This causes the operating system to run it in the console subsystem, which allocates a console for the executable when it runs. At the same time it chooses a different entry point from the runtime library for the relevant subsystem, which in turn calls main() when the program runs.

Share this post


Link to post
Share on other sites

This topic is 3590 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this