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
DispatchMessage seems to now contain a SEH try catch block that inhibits exceptions generated by window procs.
You can still catch these exceptions in the debugger - depending on your visual studio version you need to open the debug->exceptions dialog and tick the "Break when an exception is thrown" column for all Win32 exceptions, or at least exception 0xc0000005
I've noticed that, when you have Aero enabled (which is by default in Vista), resizing windows tends to create many, many page faults. These aren't normal virtual memory-needs-to-be-paged-in faults, either. I suspect (though it's just a theory), that Aero redirects the graphics output to a protected chunk of memory, and catches the faults in order to know which bits of the visible surface need to be recomposited on the desktop. Perhaps that is eating other access violations as well.
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; }
Starting from XP, the Vector Exception Handling functionality can be used. It has priority over all other kinds of exceptions. In my example, it correctly caught the Access Violation in the WM_PAINT message. Unfortunately, it also catches all other kinds of exceptions, which I should probably solve by checking for the exception code.
Exception will be thrown in WinXP and in Vista. I've just tested this in Vista in Debug and Release configurations. Do you have the same issue in new Win32 Application project?
It's a known defect. Check the hotfix. http://support.microsoft.com/kb/976038