简体   繁体   English

0x00007FF8956DA430 (user32.dll) 处的未处理异常

[英]Unhandled exception at 0x00007FF8956DA430 (user32.dll)

I get an error when trying to load my Window Application, the error is called "Unhandled exception at 0x00007FF8956DA430 (user32.dll) in Tennis.exe: 0xC0000005: Access violation reading location"尝试加载我的 Window 应用程序时出现错误,该错误称为“Tennis.exe 中 0x00007FF8956DA430 (user32.dll) 处未处理的异常:0xC0000005:访问冲突读取位置”

Windows.cpp - Windows.cpp -

Windows32::Windows32()
{
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)

{
    switch (msg)
    {
    case WM_CREATE:
    {   Windows32* window = (Windows32*)((LPCREATESTRUCT)lparam)->lpCreateParams;
        SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)window);
        window->onCreate();
        break;
       // case WM_CREATE;
    }

    case WM_DESTROY:
    {   
        Windows32* window = (Windows32*)GetWindowLong(hwnd, GWLP_USERDATA);
        window->onDestroy();
        ::PostQuitMessage(0);
        break;
    }

    default:
        return ::DefWindowProc(hwnd, msg, wparam, lparam);

    }

    return NULL;
}



bool Windows32::init()
{
    WNDCLASSEX wc;
    wc.cbClsExtra = NULL;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.cbWndExtra = NULL;
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wc.hInstance = NULL;
    wc.lpszClassName = L"MyWindows32Class";
    wc.lpszClassName = L"";
    wc.style = NULL;
    wc.lpfnWndProc = &WndProc;


    if (!::RegisterClassEx(&wc))
        return false;

   // if (!window)
     //   window = this;


    m_hwnd=::CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, L"MyWindows32Class", L"DirectX Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768,
        NULL, NULL, NULL, this);


  
    if (!m_hwnd)
        return false;

    ::ShowWindow(m_hwnd, SW_SHOW);
    ::UpdateWindow(m_hwnd);

    //::RegisterClassEx(&wc);
 

  
    
    m_is_run = true;
    return true;
}

bool Windows32::broadcast()
{
    MSG msg;

    this->onUpdate();

    while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }


    Sleep(1);
    return true;
}


bool Windows32::release()
{
    if (!::DestroyWindow(m_hwnd))
        return false;
    return true;
}

bool Windows32::isRun()
{
    return m_is_run;
}

void Windows32::onCreate() {

}

void Windows32::onUpdate() {

}
void Windows32::onDestroy()
{
    m_is_run = false;
}

Windows32::~Windows32() {

}

Windows.h Windows.h



#pragma once
#include <Windows.h>
class Windows32 
{
public:
    Windows32();
    bool init();
    bool broadcast();
    bool release();
    bool isRun();

    virtual void onCreate();
    virtual void onUpdate();
    virtual void onDestroy();




    ~Windows32();
protected:
    HWND m_hwnd;
    bool m_is_run;
};

Main.cpp主.cpp

#include "Windows32App.h"

int main() {
    Windows32App app;
    if (app.init())
    {
        while (app.isRun())
        {
            app.broadcast();
        }
    }
    
    return 0;
}

WindowsApp.h Windows应用程序h

#pragma once
#include "Windows32.h"


class Windows32App: public Windows32
{
public:
   Windows32App();
   ~Windows32App();



// Inherited via Windows32
virtual void onCreate() override;
virtual void onUpdate() override;
virtual void onDestroy() override;

}; };

Windows32App.cpp Windows32App.cpp

#include "Windows32App.h"



Windows32App::Windows32App()
{
}

Windows32App::~Windows32App()
{
}

void Windows32App::onCreate()
{
Windows32::onCreate();
}

void Windows32App::onUpdate()
{
Windows32::onUpdate();
}

void Windows32App::onDestroy()
{
Windows32::onDestroy();
}

I have tried searching up on the inte.net and looking for answers and I have tried the debugger我试过在 inte.net 上搜索并寻找答案,我试过调试器

You have to implement constructor which creates Window32 from HWND .您必须实现从HWND创建Window32的构造函数。 If you simply cast HWND to Window32* , then it could lead to segfault because you write to and read from memory that is outside the bounds of the area that hwnd points to.如果您只是将HWND转换为Window32* ,那么它可能会导致段错误,因为您在hwnd指向的区域边界之外写入和读取 memory。 In other words, your cast will not automatically create Window32 from HWND .换句话说,您的转换不会自动从HWND创建Window32 Here is my suggestion:这是我的建议:

public:
    Windows32(HWND hWnd)
    {
        this->m_hwnd = hWnd;
        this->m_is_run = true;
    }

Use利用

Windows32 window(((LPCREATESTRUCT)lparam)->lpCreateParams);

instead反而

Windows32* window = (Windows32*)((LPCREATESTRUCT)lparam)->lpCreateParams;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 卡在0x00007FF74F27A526处有未处理的异常:堆栈溢出 - Stuck with Unhandled exception at 0x00007FF74F27A526 : Stack Overflow C++ 乘以 BigInt - 在 0x00007FFD777FF530 (ucrtbased.dll) 处引发异常 - C++ multiplying BigInt - Exception thrown at 0x00007FFD777FF530 (ucrtbased.dll) SFML 2.2未处理的异常位于0x00007FFA622C21F9(sfml-system-2.dll) - SFML 2.2 Unhandled exception at 0x00007FFA622C21F9(sfml-system-2.dll) LoadLibrary(&#39;user32.dll&#39;)返回14007 - LoadLibrary('user32.dll') returns 14007 msdn说的user32.dll是吗? - Is user32.dll the “WinApi” msdn speaks of? C ++ appcrash USER32.dll - C++ appcrash USER32.dll 在0x00007FF746DA221B SDL_game.exe中引发异常:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF - Exception thrown at 0x00007FF746DA221B SDL_game.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF 窗口的user32.dll的translationmessage()API在64位中引发的第一次机会异常 - first chance exception thrown from translatemessage() api of window's user32.dll in 64 bit 在 0x00007FF93E507A7A (ntdll.dll) 抛出异常。访问冲突读取位置 0xFFFFFFFFFFFFFFFF - Exception thrown at 0x00007FF93E507A7A (ntdll.dll) .Access violation reading location 0xFFFFFFFFFFFFFFFF SOIL未处理的异常,位于0x585727FF - SOIL Unhandled exception at 0x585727FF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM