3 c++ winapi codeblocks winmain
所以我尝试使用 Win32 在CodeBlocks中创建一个窗口,到目前为止只有这个版本的 WinMain 可以工作(注意:这只是一个简单而幼稚的示例):
#include <windows.h>
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow ) {
MessageBox( NULL, "Title", "Message", MB_OKCANCEL );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但这个版本没有:
#include <windows.h>
INT WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow ) {
MessageBox( NULL, "Title", "Message", MB_OKCANCEL );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,后者期望第三个参数是指向宽字符字符串的指针,而前者则不然。但是当我在 CodeBlocks 中编译时,我得到的只是这条消息:
对 WinMain@16 的未定义引用
显然,CodeBlocks 期望 WinMain 的版本不接收 LPWSTR 值作为参数。我的问题是,如何配置 CodeBlocks 以便它与 wWinMain 一起编译?
wWinMain是编译器特定的。它受 Visual Studio 支持。Code::Block 通常使用 MinGW 设置,它会编译,wWinMain但会给出链接错误,因为它无法识别wWinMain为入口点,它仍在寻找WinMain入口点。
您可以只使用第一个版本WinMain,然后用于GetCommandLineW()Unicode 命令行。例子:
int argc;
wchar_t** argv = CommandLineToArgvW( GetCommandLineW(), &argc );
for (int i = 0; i < argc; i++)
{
//output argv[i]
}
Run Code Online (Sandbox Code Playgroud)
lpCmdLine然而和之间存在差异GetCommandLineW。查看文档
赢主:
lpCmdLine:应用程序的命令行,不包括程序名称
GetCommandLineW():当前进程的命令行字符串
请注意,如果可以的话,您应该使用 Visual Studio。免费!
| 归档时间: |
|
| 查看次数: |
2688 次 |
| 最近记录: |