2014-05-14 57 views
-1
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程序時,它的唯一功能是繪製一個窗口,其中切換光標移動和點擊,但顯示窗口後,右側的按鈕,可以前的應用程序崩潰做某事。在窗口過程中,我只有WM_COMMAND,WM_DESTROY和默認返回DefWindowProc()的情況。 WinMain函數代碼:C++ APPCRASH USER32.dll中

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; 

的HWNDs是全局變量,BTN和主要的宏。

+6

如果在調試器中運行,它會停在飛機墜毀的地方,讓你檢查變量的值,並檢查(並向上走)函數調用堆棧。做到這一點,找到(在你的代碼中)它崩潰的地方,並檢查值,看看你是否可以找出原因。 –

+0

另外,以最大警告等級('/ W4')進行編譯。你可能會做一些明顯錯誤的編譯器可以檢測到的東西。 –

+0

我用了Beep(300,300);作爲一個調試器,發現問題出在UpdateWindow(hwnd)之後。我試圖將嗶聲粘貼到GetMessage循環中,但是在嘟嘟聲之前應用程序崩潰可以發出聲音。我不知道如何處理這個問題 – user3392623

回答

2

GetMessage的參數lpMsg不允許爲NULL(0)。

這一呼籲:

while (GetMessage(0, hwnd, 0, 0)) 

需要是:

while (GetMessage(&msg, hwnd, 0, 0)) 
相關問題