“APIENTRY _tWinMain” and “WINAPI WinMain” difference

十年热恋 提交于 2019-11-27 11:57:41

_tWinMain is just a #define shortcut in tchar.h to the appropriate version of WinMain.

If _UNICODE is defined, then _tWinMain expands to wWinMain. Otherwise, _tWinMain is the same as WinMain.

The relevant macro looks something like this (there's actually a lot of other code interspersed):

#ifdef  _UNICODE
#define _tWinMain  wWinMain
#else
#define _tWinMain  WinMain
#endif

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 just GetModuleHandle(0)

hPrevInstance is not valid in Win32 anyway

lpCmdLine is available in both ANSI and Unicode, via GetCommandLineA() and GetCommandLineW(), respectively

nCmdShow is the wShowWindow parameter of the STARTUPINFO structure. Again, ANSI and Unicode variants, accessed using GetStartupInfoA(STARTUPINFOA*) and GetStartupInfoW(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:

_tWinMain actually does take the hPrevInstance parameter, but that parameter isn''t used.

_tWinMain is just a #define to WinMain (in TCHAR.h).

There is no difference between the two.

and

_tWinMain is defined to WinMain if UNICODE is not defined, and to wWinMain if it is. its purpose is to let you write code that will build both under ansi and under unicode.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!