main() entry point in Windows apps17 Nov 2013
Many times when you use external libraries to create a window for your app (for example, graphics engines like OGRE), the app doesn’t actually need to have
WinMain entry point. Moreover, if you’re going to port the app to other platforms, you’ll have to adapt the entry point to be
main() instead of
WinMain. Having the same main entry point on all platforms could be quite convenient.
On Windows only console apps normally use
main() as an entry point. They also auto-create console window, which isn’t what we want in a GUI application. The following steps in Visual Studio will make the app use
main() entry point without creating a console window:
- Open project properties
- Change “Linker -> System -> SubSystem” option to WINDOWS
- Change “Linker -> Advanced -> Entry Point” option to mainCRTStartup
The System option set to WINDOWS makes application run without a console window. The Entry Point option allows us specify what entry point the compiler should expect to find in our code (
main in this case).