C++ “APIENTRY _tWinMain”和“WINAPI WinMain”的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4681443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"APIENTRY _tWinMain" and "WINAPI WinMain" difference
提问by xRobot
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)
回答by Cody Gray
_tWinMain
is just a #define
shortcut in tchar.h to the appropriate version of WinMain
.
_tWinMain
只是#define
tchar.h 中适当版本的WinMain
.
If _UNICODE
is defined, then _tWinMain
expands to wWinMain
. Otherwise, _tWinMain
is the same as WinMain
.
如果_UNICODE
已定义,则_tWinMain
扩展为wWinMain
。否则,_tWinMain
与 相同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
回答by Ben Voigt
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)
hInstance
只是 GetModuleHandle(0)
hPrevInstance
is not valid in Win32 anyway
hPrevInstance
无论如何在 Win32 中无效
lpCmdLine
is available in both ANSI and Unicode, via GetCommandLineA()
and GetCommandLineW()
, respectively
lpCmdLine
分别通过GetCommandLineA()
和提供 ANSI 和 Unicode 版本GetCommandLineW()
nCmdShow
is the wShowWindow
parameter of the STARTUPINFO
structure. Again, ANSI and Unicode variants, accessed using GetStartupInfoA(STARTUPINFOA*)
and GetStartupInfoW(STARTUPINFOW*)
.
nCmdShow
是结构wShowWindow
参数STARTUPINFO
。同样,ANSI 和 Unicode 变体,使用GetStartupInfoA(STARTUPINFOA*)
和访问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
.
并且通过使用 Win32 API 来访问这些,您可能会保存一些全局变量,例如您小心地保存您认为仅适用于WinMain
.
回答by chrisaycock
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.
_tWinMain 实际上确实采用了 hPrevInstance 参数,但未使用该参数。
_tWinMain 只是 WinMain 的 #define(在 TCHAR.h 中)。
两者没有区别。
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.
如果未定义 UNICODE,则 _tWinMain 定义为 WinMain,如果定义了,则定义为 wWinMain。它的目的是让您编写可以在 ansi 和 unicode 下构建的代码。