隐藏未知程序崩溃

原文:https://blog.csdn.net/ren65432/article/details/45395461 

windows提供了一个如下函数:

LPTOP_LEVEL_EXCEPTION_FILTER
WINAPI
SetUnhandledExceptionFilter(
    __in_opt LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
    );

由MSDN我们可以知道:当前进程中发送任何异常时,SetUnhandledExceptionFilter都能捕获到,并将调用lpTopLevelExceptionFilter回调函数。所以在异常发送时,我们可以在lpTopLevelExceptionFilter中做我们想做的事。

LONG CallBackCrashHandler(EXCEPTION_POINTERS *pException)  
{   
	// 这里你可以做一个漂亮的界面或者其他
	MessageBox(NULL,L"崩溃了...",L"错误",MB_OK);
	return EXCEPTION_EXECUTE_HANDLER;  
}  
 
 
int _tmain(int argc, _TCHAR* argv[])  
{  
	// 设置处理Unhandled Exception的回调函数  
	SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CallBackCrashHandler); 
	return 0;  
}


 

猜你喜欢

转载自blog.csdn.net/qq_40244176/article/details/84026049