Sign in to follow this  

Entry Point

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

Hey there, I have a question. I was browsing these forums a few months ago, and I remember seeing something about Entry Points. I remember someone saying that Main() is always called BEFORE WinMain() in Windows Applications, and that you can define both. Is this true, or was I seeing things? :P

Share this post


Link to post
Share on other sites
You can define both main() and WinMain() in a project, but only one should be used. main() if the program runs in the console subsystem or WinMain() if the program runs in the windows subsystem.

Share this post


Link to post
Share on other sites
The actual entry point is defined in the header of the executable. It points to a stub of code that typically sets up an seh final handler and instances io handles if needed.

If the program is a console program (ie uses main) the stub calls getmainargs to setup the argv variable, then calls main. If the program is a gui program (ie uses WinMain) the stub calls GetModuleHandle(NULL) for the HINSTANCE and so forth and then calls WinMain.

Here's what the code for the console stub looks like crtstartup.c. For a gui program the stub function is called WinMainCRTStartup.

So as far as mixing main and WinMain, you can't. Well, you could have one call the other or not, but you can only use one stub at a time. You can have a console based program set up and instance a gui. Maybe that's where your confusion comes from?

Share this post


Link to post
Share on other sites

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