access violation in WM_PAINT not caught

前端 未结 6 825
伪装坚强ぢ
伪装坚强ぢ 2020-12-17 01:30

To test this problem I have written a minimal windows application. If I force an access violation in the WM_PAINT handler this exception never gets to the debug

6条回答
  •  太阳男子
    2020-12-17 02:07

    As a workaround I remove all registered exception handlers in my window procedure. Quite ugly.

    LRESULT CALLBACK window_proc( 
        HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
        // get thread information block
        NT_TIB* tib;
        __asm {
            mov EAX, FS:[18h]
            mov [tib], EAX
        }
        // old exception handler list
        _EXCEPTION_REGISTRATION_RECORD* old_exception_handler = tib->ExceptionList;
        // remove all exception handler with exception of the default handler
        while( tib->ExceptionList->Next != (_EXCEPTION_REGISTRATION_RECORD*)-1 ) {
            tib->ExceptionList = tib->ExceptionList->Next;
        }
    
        LRESULT result = DefWindowProc( hwnd, uMsg, wParam, lParam );
    
        // restore old exception handler
        tib->ExceptionList = old_exception_handler;
    
        return result;
    }
    

提交回复
热议问题