How does Qt manage to use main() for non-console applications in Windows?

c++, qt, windows

Solution

Qt makes use of `WinMain()` defined in `qtbase/src/winmain/qtmain_win.cpp`, which subsequently calls our "fictional" `int main(int argc, char *argv[])`.

P.S. You could figure out this kind of tricks by setting a breakpoint in the debugger, and looking at call stack. In Visual Studio: Menu "Debug" -> Windows -> Call Stack.

Problem

As Microsoft themselves explain it, console programs use `main()`, but non-console Win32 programs use `WinMain()` as the entry-point. In fact, using `main()` in a Win32 project in Visual Studio will result in a linker error. But in Qt projects, whether created from Qt Creator or Visual Studio, the GUI programs use `main()` just like the console programs. How do the Qt folks manage to do it?

Original source

Related problems