Difference between WinMain and wWinMain

Viewed 24037

The only difference is that Winmain takes char* for lpCmdLine parameter, while wWinMain takes 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?

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?

3 Answers

WinMain/wWinMain is not the real Windows entry point. Windows just calls the function specified in the PE header with zero parameters.

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.

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.

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.

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().

Related