What are the difference from these 2 function?:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
The difference is the encoding of the parameters, which are completely redundant anyway. Just throw away the parameters and instead use the following, where you control the encoding:
hInstance
is justGetModuleHandle(0)
hPrevInstance
is not valid in Win32 anywaylpCmdLine
is available in both ANSI and Unicode, viaGetCommandLineA()
andGetCommandLineW()
, respectivelynCmdShow
is thewShowWindow
parameter of theSTARTUPINFO
structure. Again, ANSI and Unicode variants, accessed usingGetStartupInfoA(STARTUPINFOA*)
andGetStartupInfoW(STARTUPINFOW*)
.And by using the Win32 APIs to access these, you're probably going to save a few global variables, like the one where you were carefully saving the instance handle you thought was only available to
WinMain
.From this link:
and
_tWinMain
is just a#define
shortcut in tchar.h to the appropriate version ofWinMain
.If
_UNICODE
is defined, then_tWinMain
expands towWinMain
. Otherwise,_tWinMain
is the same asWinMain
.The relevant macro looks something like this (there's actually a lot of other code interspersed):