Jump to content
  • Advertisement
Sign in to follow this  
Lenox

Entry Point

This topic is 4702 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!