windows WinMain 和 wWinMain 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1792275/
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
Difference between WinMain and wWinMain
提问by cuteCAT
The only difference is that Winmain takes char* for lpCmdLine parameter, while wWinMain takes wchar_t*.
唯一的区别是 Winmain 使用 char* 作为 lpCmdLine 参数,而 wWinMain 使用 wchar_t*。
On Windows XP, if an application entry is WinMain, does Windows convert the command line from Unicode to Ansi and pass to the application?
在 Windows XP 上,如果应用程序入口是 WinMain,Windows 是否会将命令行从 Unicode 转换为 Ansi 并传递给应用程序?
If the command line parameter must be in Unicode (for example, Unicode file name, conversion will cause some characters missing), does that mean that I must use wWinMain as the entry function?
如果命令行参数必须是Unicode(比如Unicode文件名,转换会导致部分字符丢失),是不是就必须使用wWinMain作为入口函数?
采纳答案by Joey
On Windows XP, if an application entry is WinMain, does Windows convert the command line from Unicode to Ansi and pass to the application?
在 Windows XP 上,如果应用程序入口是 WinMain,Windows 是否会将命令行从 Unicode 转换为 Ansi 并传递给应用程序?
Yes.
是的。
If the command line parameter must be in Unicode (for example, Unicode file name, conversion will cause some characters missing), does that mean that I must use wWinMain as the entry function?
如果命令行参数必须是Unicode(比如Unicode文件名,转换会导致部分字符丢失),是不是就必须使用wWinMain作为入口函数?
Yes, you should, if you want to correctly handle Unicode arguments to your program.
是的,如果您想正确处理程序的 Unicode 参数,您应该这样做。
The documentation to WinMain() on MSDNalso agrees.
You can, however, also use GetCommandLineW to retrieve the command line specifically in Unicode.
但是,您也可以使用 GetCommandLineW 专门检索 Unicode 中的命令行。
回答by Anders
WinMain
/wWinMain
is not the real Windows entry point. Windows just calls the function specified in the PEheader with zero parameters.
WinMain
/wWinMain
不是真正的 Windows 入口点。Windows 只是使用零参数调用PE标头中指定的函数。
When using the Microsoft tool chain this is void WinMainCRTStartup() { ... }
when you are creating a GUI application and it is provided for you unless you link with /Zl.
使用 Microsoft 工具链时,这是void WinMainCRTStartup() { ... }
在创建 GUI 应用程序时为您提供的,除非您与/Zl链接。
The default WinMainCRTStartup
code created by Visual C++ initializes the C run-time library, calls global constructors (if any) and then calls your WinMain
/wWinMain
function with a HINSTANCE
from GetModuleHandle(NULL)
, the command line from GetCommandLineA/W()
(skipping the over the filename in the command line) and the show command from GetStartupInfo
.
WinMainCRTStartup
Visual C++ 创建的默认代码初始化 C 运行时库,调用全局构造函数(如果有),然后使用from 、命令行 from (跳过命令行中的文件名)和 show调用您的WinMain
/wWinMain
函数命令来自.HINSTANCE
GetModuleHandle(NULL)
GetCommandLineA/W()
GetStartupInfo
The only difference between WinMain
and wWinMain
is the command line string and you should use wWinMain
in Unicode applications (and all applications created these days should use Unicode). You can of course manually call GetCommandLineW()
in WinMain
and parse it yourself if you really want to.
WinMain
和之间的唯一区别wWinMain
是命令行字符串,您应该wWinMain
在 Unicode 应用程序中使用(并且现在创建的所有应用程序都应该使用 Unicode)。你当然也可以手动调用GetCommandLineW()
在WinMain
和自己解析它,如果你真的想。
In Windows NT/2000/XP and later the command line is a Unicode string internally and WinMain
/GetCommandLineA()
gives you a converted version of this which might not be able to represent every single character correctly. On Windows 95/98/ME it is the other way around but GetCommandLineW()
is always able to convert every character from GetCommandLineA()
.
在 Windows NT/2000/XP 及更高版本中,命令行在内部是一个 Unicode 字符串,WinMain
/GetCommandLineA()
为您提供一个转换版本,它可能无法正确表示每个字符。在 Windows 95/98/ME 上则相反,但GetCommandLineW()
始终能够将每个字符从GetCommandLineA()
.
回答by t0mm13b
Windows XP upwards is unicode by default! And thus, no conversion is required. The C++ Runtime loader takes care of the argument passing to the application. Standard Win32 API dictates that the main entry is WinMain(...).
Windows XP 以上默认是unicode!因此,不需要转换。C++ 运行时加载器负责传递给应用程序的参数。标准 Win32 API 规定主条目是 WinMain(...)。