C++;appcrash USER32.dll 我尝试制作C++ WiNAPI程序,它的唯一功能是用一个按钮来切换窗口,它可以移动光标移动和点击,但是在显示窗口之后,应用程序在能够做某事之前崩溃。在window过程中,我只有WM_命令、WM_DESTROY和默认返回DefWindowProc()案例。WinMain函数代码: Problem Event Name: APPCRASH Application Name: program.exe Application Version: 0.0.0.0 Application Timestamp: 537374b6 Fault Module Name: USER32.dll Fault Module Version: 6.3.9600.16384 Fault Module Timestamp: 52157ca5 Exception Code: c0000005 Exception Offset: 0000949d OS Version: 6.3.9600.2.0.0.256.48 Locale ID: 1049 Additional Information 1: 5861 Additional Information 2: 5861822e1919d7c014bbb064c64908b2 Additional Information 3: 3a20 Additional Information 4: 3a20a93c34687143a5bf7d33f1cf3ccc
HWND是全局变量,BTN和MAIN是宏。GetMessage的C++;appcrash USER32.dll 我尝试制作C++ WiNAPI程序,它的唯一功能是用一个按钮来切换窗口,它可以移动光标移动和点击,但是在显示窗口之后,应用程序在能够做某事之前崩溃。在window过程中,我只有WM_命令、WM_DESTROY和默认返回DefWindowProc()案例。WinMain函数代码: Problem Event Name: APPCRASH Application Name: program.exe Application Version: 0.0.0.0 Application Timestamp: 537374b6 Fault Module Name: USER32.dll Fault Module Version: 6.3.9600.16384 Fault Module Timestamp: 52157ca5 Exception Code: c0000005 Exception Offset: 0000949d OS Version: 6.3.9600.2.0.0.256.48 Locale ID: 1049 Additional Information 1: 5861 Additional Information 2: 5861822e1919d7c014bbb064c64908b2 Additional Information 3: 3a20 Additional Information 4: 3a20a93c34687143a5bf7d33f1cf3ccc,c++,winapi,visual-studio-2013,C++,Winapi,Visual Studio 2013,HWND是全局变量,BTN和MAIN是宏。GetMessage的lpMsg参数不允许为空(0) 此电话: WNDCLASSEX wcx; int X, Y; MSG msg; RECT srect; GetWindowRect(GetDesktopWindow(), &srect); X = srect.right; Y = srect.bottom; wcx.cbSize = sizeof(WNDCLASSEX);
lpMsg
参数不允许为空(0)
此电话:
WNDCLASSEX wcx;
int X, Y;
MSG msg;
RECT srect;
GetWindowRect(GetDesktopWindow(), &srect);
X = srect.right;
Y = srect.bottom;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW;
wcx.lpfnWndProc = MainProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hinst;
wcx.hIcon = 0;
wcx.hCursor = 0;
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcx.lpszMenuName = 0;
wcx.lpszClassName = L"wcname";
wcx.hIconSm = 0;
if (!RegisterClassEx(&wcx)){
MessageBox(0, L".", L"RegisterClass failed", 0);
return 1;
}
hwnd = CreateWindowEx(
0,
L"wcname",
L"off",
WS_OVERLAPPEDWINDOW,
X / 2 - 112,
Y / 2 - 40,
224,
80,
0,
0,
hinst,
0
);
if (!hwnd){
MessageBox(0, L".", L"CreateWindow failed", 0);
return 1;
}
GetClientRect(hwnd, &srect);
X = srect.right;
Y = srect.bottom;
btn = CreateWindowEx(
0,
L"button",
L"Turn on",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
0, 0,
X, Y,
hwnd,
(HMENU)BTN,
hinst,
0
);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(0, hwnd, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
需要:
while (GetMessage(0, hwnd, 0, 0))
如果在调试器中运行,它将在崩溃处停止,让您检查变量的值,并检查(并向上走)函数调用堆栈。这样做可以找到它崩溃的位置(在代码中),并检查值以确定原因。另外,以最大警告级别(
/W4
)编译。你可能做了一些编译器可以检测到的明显错误的事情;作为调试器,发现问题是在UpdateWindow(hwnd)之后。我试图将beep粘贴到GetMessage循环中,但应用程序在beep发出声音之前崩溃。我不知道该怎么办你在一个非常低的内存地址有一个访问冲突。可能是未初始化的变量或空指针取消引用。我在GetMessage函数中忘记了msg变量。非常感谢你的回答,非常愚蠢的错误。
while (GetMessage(&msg, hwnd, 0, 0))