First things first: The symbols main
and WinMain
are conventions1. Using either one, or even a completely different symbol as the entry point, doesn't change anything about the program. Specifically, the entirety of the Windows API is available, irrespective of the entry point symbol chosen.
The convention becomes contractual when relying on a runtime. The overwhelming majority of applications written in C use the C Runtime (CRT). Microsoft's CRT implementation requires that programs provide an entry point called main
or WinMain
(or the respective Unicode variants) that it can call once initialized.
Whether Microsoft's CRT requires main
or WinMain
is based off of the /SUBSYSTEM linker option. When targeting the CONSOLE
subsystem, the CRT requires the symbol main
. Conversely, when targeting the WINDOWS
subsystem, it requires WinMain
.
An executable image targeting either the CONSOLE
or the WINDOWS
subsystem is identical, with a single exception: The OS will automatically allocate a console for a program that targets the CONSOLE
subsystem, and will not allocate a console for a program that targets the WINDOWS
subsystem. Everything else is all the same.
However, is this form also legal?
Yes, this is perfectly legal. Everything works just the same (modulo the arguments passed into the entry point), but the system will allocate a console for you. Particularly for learning this is a nice ad-hoc solution to get printf
-style logging/tracing.
1 WinMain is just the conventional name for the Win32 process entry point