使用 wmainUsing wmain

Microsoft 专用Microsoft Specific

在 Unicode 编程模型中,可以定义 main 函数的宽字符版本。In the Unicode programming model, you can define a wide-character version of the main function. 如果要编写符合 Unicode 编程模型的可移植代码,请使用 wmain 而不是 main。Use wmain instead of main if you want to write portable code that adheres to the Unicode programming model.

语法Syntax

wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )  

备注Remarks

使用与 main 的相似格式声明 wmain 的形参。You declare formal parameters to wmain using a similar format to main. 然后可以将宽字符自变量和宽字符环境指针(可选)传递给该程序。You can then pass wide-character arguments and, optionally, a wide-character environment pointer to the program. wmain 的 argvenvp 参数为 wchar_t* 类型。The argv and envp parameters to wmain are of type wchar_t*. 例如:For example:

如果程序使用 main 函数,则多字节字符环境由运行时库在程序启动时创建。If your program uses a main function, the multibyte-character environment is created by the run-time library at program startup. 环境的宽字符副本仅在需要时创建(如调用 _wgetenv_wputenv 函数时)。A wide-character copy of the environment is created only when needed (for example, by a call to the _wgetenv or _wputenv functions). 在首次调用 _wputenv 或首次调用 _wgetenv 时(如果 MBCS 环境已存在),会创建一个对应的宽字符字符串环境,然后通过 _wenviron 全局变量指向该环境,此变量是 _environ 全局变量的宽字符版本。On the first call to _wputenv, or on the first call to _wgetenv if an MBCS environment already exists, a corresponding wide-character string environment is created and is then pointed to by the _wenviron global variable, which is a wide-character version of the _environ global variable. 此时,同时存在该环境的两个副本(MBCS 和 Unicode),在程序的整个生存期这两个副本由操作系统维护。At this point, two copies of the environment (MBCS and Unicode) exist simultaneously and are maintained by the operating system throughout the life of the program.

同样,如果程序使用 wmain 函数,则在程序启动时创建宽字符环境并用 _wenviron 全局变量指向该环境。Similarly, if your program uses a wmain function, a wide-character environment is created at program startup and is pointed to by the _wenviron global variable. MBCS (ASCII) 环境是在首次调用 _putenvgetenv 时创建的,并由 _environ 全局变量指向。An MBCS (ASCII) environment is created on the first call to _putenv or getenv, and is pointed to by the _environ global variable.

有关 MBCS 环境的详细信息,请参阅《运行时库参考》中的国际化For more information on the MBCS environment, see Internationalization in the Run-Time Library Reference.

结束 Microsoft 专用END Microsoft Specific

请参阅See Also

main 函数和程序执行main Function and Program Execution