long MyFilter(long excode, _EXCEPTION_POINTERS *ep) { char buf[100] = {0}; if (excode == EXCEPTION_ACCESS_VIOLATION) { _EXCEPTION_RECORD* er = ep->ExceptionRecord; sprintf(buf, "AV at: 0x%08x, from: 0x%08x", er->ExceptionInformation[1] /* Invalid Address */, ep->ContextRecord->Eip); MessageBox(0, buf, "exception", 0); return EXCEPTION_EXECUTE_HANDLER; } return EXCEPTION_CONTINUE_SEARCH; }
int main(int argc, _TCHAR* argv[]) { long* a = (long*)0x555555; __try { *a = 0x1234; } __except(MyFilter(GetExceptionCode(), GetExceptionInformation())) { MessageBox(0, "ah uh", "exception", 0); } return 0; } |