Process finished with exit code -1073740771 (0xC000041D)(已解决)

我用c++代码写了一个窗口,结果在执行时会突然崩掉,报错Process finished with exit code -1073740771 (0xC000041D)

​
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
    switch(msg) {
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        case WM_PAINT:
            break;
        default:
            return DefWindowProc(hwnd, msg, wp, lp);
    }
}

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    WNDCLASS ClassForWindow = {};
    ClassForWindow.lpfnWndProc = WindowProcedure;
    ClassForWindow.hInstance = hinstance;
    ClassForWindow.lpszClassName = "ClassForWindow";
    RegisterClass(&ClassForWindow);
    HWND hwnd = CreateWindowEx(0, "ClassForWindow", "window", WS_OVERLAPPEDWINDOW, 0, 0, 800, 608,nullptr, nullptr, hinstance, nullptr);
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    MSG msg = {};
    while (GetMessage(&msg, nullptr, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

​

解决方案

是第五和第七行的break碍了事,改一下

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
    switch(msg) {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 1;    //如果返回非零值,Windows认为消息已经被处理,不会再调用DefWindowProc
        case WM_PAINT:
            //空着就行(至少现在不用)
        default:
            return DefWindowProc(hwnd, msg, wp, lp);
    }
}

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    WNDCLASS ClassForWindow = {};
    ClassForWindow.lpfnWndProc = WindowProcedure;
    ClassForWindow.hInstance = hinstance;
    ClassForWindow.lpszClassName = "ClassForWindow";
    RegisterClass(&ClassForWindow);
    HWND hwnd = CreateWindowEx(0, "ClassForWindow", "window", WS_OVERLAPPEDWINDOW, 0, 0, 800, 608,nullptr, nullptr, hinstance, nullptr);
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    MSG msg = {};
    while (GetMessage(&msg, nullptr, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值