VS2005中无效参数这种异常,无法捕获。不知该如何处理LPTOP_LEVEL_EXCEPTION_FILTER g_previousFilter = 0;
void CUnExcept_DemoDlg::OnBnClickedOk()
{
g_previousFilter = SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
//DisableSetUnhandledExceptionFilter(); 网上查询说hook_api 阻止 2005 调用
// SetUnhandledExceptionFilter(NULL),但仍然无用
此种异常可以捕获
#if 0
CString a;
a.Format(_T("%s"),1);
#endif
#if 0
CString aa = "12345678";
CHAR ID[7]={0};
strcpy(ID,(LPCTSTR)aa);
#endif
此种异常就无法捕获
}
void DisableSetUnhandledExceptionFilter()
{
void *addr = (void*)GetProcAddress(LoadLibrary(_T("kernel32.dll")),
"SetUnhandledExceptionFilter");
if (addr)
{
unsigned char code[16];
int size = 0;
//xor eax,eax;
code[size++] = 0x33;
code[size++] = 0xC0;
//ret 4
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);
}
}
湖北武汉