Talking about the Microsoft toolchain, conventionally, Win32 graphical applications have always started with WinMain
, while main
is used for console applications.
The difference between the two kinds of applications actually boils down (mostly) to a single setting in the executable, and is not in capability - a GUI application can create a console, and a console application can create a window - but in the behavior of the loader: for an exe marked as GUI the loader won't allocate any console, while a console exe will attach to the parent's console or create a new one if there isn't one.
For the entrypoint name, it is all just a matter of linker/CRT defaults: the "real" entry point of the executable is just an offset into the final executable, that points to a function that takes no parameters. It's the CRT that does its stuff, determines the parameters and then calls "your" entrypoint, so, in line of principle, they both could work exactly the same way.
The point is, the name/signature of the default entrypoint that the CRT looks for depends from the type of application you are building; if the compiler and linker are set to build a console application, they will look for a main
(or wmain
or _tmain
, depending on Unicode settings), for a GUI application they use WinMain
, and DllMain
for a dll.
So:
- use
WinMain
if you are building a GUI (=no console created for it at startup) application;
main
for a console application;
DllMain
for a dll.
Again, this all isn't written in stone (and there are ways to start a GUI application from a standard main
), but "when in Rome, do as the Romans do" - i.e. it's usually best to follow the uses of the platform to avoid confusing other developers and going through untested/unsupported compiler settings just to change the signature of the entrypoint.