这两个function有什么不同?
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
_tWinMain
只是tchar.h中的一个#define
快捷方式,适用于WinMain
的相应版本。
如果定义了_UNICODE
,则_tWinMain
将扩展为wWinMain
。 否则, _tWinMain
和WinMain
是一样的。
相关的宏看起来像这样(实际上有很多其他代码散布):
#ifdef _UNICODE #define _tWinMain wWinMain #else #define _tWinMain WinMain #endif
不同之处在于参数的编码,无论如何都是完全冗余的。 只要扔掉参数,而是使用下面的代码来控制编码:
hInstance
只是GetmoduleeHandle(0)
无论如何, hPrevInstance
在Win32中无效
lpCmdLine
分别通过GetCommandLineA()
和GetCommandLineW()
在ANSI和Unicode中可用
nCmdShow
是STARTUPINFO
结构的wShowWindow
参数。 同样,使用GetStartupInfoA(STARTUPINFOA*)
和GetStartupInfoW(STARTUPINFOW*)
访问ANSI和Unicode变体。
通过使用Win32 API来访问这些API,你可能会保存一些全局变量,比如那些你认为只保存WinMain
的实例WinMain
。
从这个链接 :
_tWinMain实际上并不使用hPrevInstance参数,但该参数不被使用。
_tWinMain只是WinMain的一个#define(在TCHAR.h中)。
两者没有区别。
和
如果UNICODE没有定义,_tWinMain被定义为WinMain,如果是则定义为wWinMain。 它的目的是让你编写在ansi和unicode下都可以编译的代码。