WinMain compiles, but wWinMain does not in CodeBlocks
本问题已经有最佳答案,请猛点这里访问。
因此,我试图使用Win32在CodeBlocks中创建一个窗口,到目前为止,只有此版本的WinMain可以工作(注意:这只是一个简单而天真的示例):
1 2 3 4 5 6 | #include <windows.h> INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow ) { MessageBox( NULL,"Title","Message", MB_OKCANCEL ); return 0; } |
但是此版本不:
1 2 3 4 5 6 | #include <windows.h> INT WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow ) { MessageBox( NULL,"Title","Message", MB_OKCANCEL ); return 0; } |
据我所知,后者期望第三个参数是指向一串宽字符的指针,而前者则不然。 但是当我在CodeBlocks中编译时,我得到的只是以下消息:
undefined reference to WinMain@16
显然,CodeBlocks期望WinMain的版本不接收LPWSTR值作为参数。
我的问题是,我该如何配置CodeBlocks以便使用wWinMain进行编译?
您可以仅使用
1 2 3 4 5 6 | int argc; wchar_t** argv = CommandLineToArgvW( GetCommandLineW(), &argc ); for (int i = 0; i < argc; i++) { //output argv[i] } |
但是
WinMain:
lpCmdLine : The command line for the application, excluding the program name
GetCommandLine:
GetCommandLineW() : The command-line string for the current process
注意,如果可以,您应该使用Visual Studio。 免费!