Replacing WinMain() with main() function in Win32 programs
Solution 1:
You can use standard main
in a "windows" app (that is, a GUI subsystem Windows application) even with the Microsoft tools, if you add the following to the Microsoft linker options:
/subsystem:windows /ENTRY:mainCRTStartup
Note that this is not necessary for the GNU toolchain.
Still for the Microsoft tools you can alternatively add this to your main file:
#ifdef _MSC_VER
# pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
James McNellis tells you how to get the hInstance.
Solution 2:
GetModuleHandle(NULL)
will give you hInstance
. hPrevInstance
is always NULL
.