“APIENTRY_tWinMain”和“WINAPI WinMain”不同之处
这两个函数有什么区别?:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
_tWinMain
只是 tchar.h 中WinMain
相应版本的#define
快捷方式。如果
定义 _UNICODE
后,_tWinMain
扩展为wWinMain
。否则,_tWinMain
与WinMain
相同。相关的宏看起来像这样(实际上散布着很多其他代码):
_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):
区别在于参数的编码,无论如何都是完全冗余的。只需丢弃参数,而是使用以下内容,您可以在其中控制编码:
hInstance
is justGetModuleHandle(0)
hPrevInstance
is not valid in无论如何,Win32lpCmdLine
在 ANSI 和 Unicode 中均可用,分别通过GetCommandLineA()
和GetCommandLineW()
nCmdShow
是STARTUPINFO
结构的wShowWindow
参数。同样,使用GetStartupInfoA(STARTUPINFOA*)
和GetStartupInfoW(STARTUPINFOW*)
访问 ANSI 和 Unicode 变体。通过使用 Win32 API 访问这些变量,您可能会保存一些全局变量,例如您小心保存的实例句柄,您认为该句柄仅适用于
WinMain
。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
这是 Ben Voigt 建议的包装器,无需智能配置和链接即可工作。
Here is the wrapper as suggested by Ben Voigt, works w/o intelligent configuring and linking.