具体报错如下

具体代码如下


尝试过修改字符集,mfc,以及预处理器定义与子系统。仍没解决问题
具体报错如下



下午好🌅🌅🌅
本答案参考ChatGPT-3.5
问题中提到了LNK2019错误,错误信息为无法解析的外部符号 main,函数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中引用了该符号。
这个错误通常发生在缺少main函数的情况下,或者main函数的声明与定义不匹配的情况下。
解决方案:
修改后的代码示例:
#include <Windows.h>
HINSTANCE hinst;
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wCx;
HWND hwnd;
MSG msg;
BOOL fGotMessage;
wCx.cbSize = sizeof(wCx);
wCx.style = CS_HREDRAW | CS_VREDRAW;
wCx.lpfnWndProc = MainWndProc;
wCx.cbClsExtra = 0;
wCx.cbWndExtra = 0;
wCx.hInstance = hinstance;
wCx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wCx.hCursor = LoadCursor(NULL, IDC_ARROW);
wCx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wCx.lpszMenuName = NULL;
wCx.lpszClassName = L"MainWinClass";
wCx.hIconSm = (HICON)LoadImage(hinstance, MAKEINTRESOURCE(5), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
if (!RegisterClassEx(&wCx))
return 1;
hwnd = CreateWindow(L"MainWinclass", L"Hello", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HmND)NULL, (HMENU)NULL, hinstance, (LPVOID)NULL);
if (!hwnd)
return 1;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while ((fGotMessage = GetMessage(&msg, (HWND)NULL, 0, 0)) != 0 && fGotMessage != -1) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
希望以上解决方案能够帮助你解决问题。如果问题还未解决,请提供更多的错误信息和代码细节,以便更好地帮助你。