|I want to log some information before the application crashes. I find the function SetUnhandledExceptionFilter() in MSDN, which enables an application to supersede the top-level exception handler of each thread and process. I'm not sure whether it can catch all exception in a MFC application or not.
I also found some articles about SetUnhandledExceptionFilter in VS2005. It seems that we need to disable the SetUnhandledExceptionFilter function called by CRT. The code is as follows:
void *addr = (void*)GetProcAddress(LoadLibrary(_T("kernel32.dll")),
unsigned char code;
int size = 0;
code[size++] = 0x33;
code[size++] = 0xC0;
code[size++] = 0xC2;
code[size++] = 0x04;
code[size++] = 0x00;
DWORD dwOldFlag, dwTempFlag;
VirtualProtect(addr, size, PAGE_READWRITE, &dwOldFlag);
WriteProcessMemory(GetCurrentProcess(), addr, code, size, NULL);
VirtualProtect(addr, size, dwOldFlag, &dwTempFlag);
I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00". Who does understand the code?
In addition, when I debug the code to catch exception, a exception dialog will ask me "Abort, Retry or Ignore". If I select "Abort" or "Ignore', my defined exception funciton will not call. Instead I want it will be called in any case.
So is there some solution for my requirement? Thanks!