我的程序中断并这样说
Unhandled exception at 0x00f85069 in Monopoly.exe: 0xC0000005: Access violation writing location 0x0000000c.
我制作了一个 win32 包装器。我有两个 WndProc,一个是静态的,另一个不是。静态 WndProc 调用非静态 WndProc。当我尝试获取消息时它工作正常但是当我尝试为某物设置一个值时它抛出异常。
这是我的两个 WndProc 的代码(第一个是静态的)
LRESULT CALLBACK Window::StaticWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
if ( msg == WM_CREATE )
{
SetWindowLongPtr( hWnd, GWLP_USERDATA, (LONG)((CREATESTRUCT *)lParam)->lpCreateParams );
}
Window *targetApp = (Window*)GetWindowLongPtr( hWnd, GWLP_USERDATA );
return targetApp->WndProc( hWnd, msg, wParam, lParam );
}
LRESULT CALLBACK Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
z=-14; //IT THROW EXCEPTION
break;
case WM_RBUTTONDOWN:
z-=1;
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
提前致谢
编辑:
变量
int z;
最佳答案
您如何创建窗口?您是否传递了指向 Window
实例的有效指针?给你的CreateWindow()
或 CreateWindowEx()
通过 lpParam
运行范围?例如,如果您的窗口包装器有一个 Create()
功能或类似的东西:
void Window::Create()
{
/* ... */
// Pass a pointer to ourselves to CreateWindow() via the lpParam parameter.
// CreateWindow() then passes that pointer to your window procedure
// (StaticWndProc) via WM_CREATE and WM_NCCREATE in the lpCreateParams member
// of CREATESTRUCT. This way the window procedure will know which instance to
// call WndProc() on.
CreateWindow(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight,
hWndParent, hMenu, hInstance, (LPVOID)this);
/* ... */
}
关于c++ - 在 0x00f85069 处获取未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4235510/