编译错误C2664或C2731 c++ 2015

Compiler Error C2664 or C2731 C++ 2015

本文关键字:c++ 2015 C2731 错误 C2664 编译      更新时间:2023-10-16

我已经能够细化WinMain函数。现在我想做一个win32应用程序:

#include <Windows.h>
int WINAPI WinMain() {
    MessageBox(NULL,"Test", "Hello World", NULL);
    return 0;
}

然后我得到错误C2731

您没有为WinMain()方法提供任何参数,并且错误C2731说该方法不能重载。

从MSDN:

int WINAPI WinMain(HINSTANCE hInstance,
               HINSTANCE hPrevInstance,
               LPSTR lpCmdLine,
               int nCmdShow);

错误C2664最有可能是你对MessageBox的调用,所以尝试更改为:

MessageBox(NULL, L"Test", L"Hello World", NULL);

我发现我没有使用main.cpp作为我的主要源代码文件,我的WinMain需要切换到wWinMain