在Windows XP系统里,如果一个程序出错了,就会产生一个程序错误报告,并且可以发送到微软去。对于用户自己开发的程序出错,并不需要发送到微软去,因为那样做是没有什么作用的,毕竟微软不会帮我们改正程序的,那么怎么样来修改出错时不发送到弹出程序出错报告呢?现在就来看看第二人生里是怎么样实现的吧。它的代码如下:
#001 void LLAppViewerWin32::disableWinErrorReporting()
#002 {
#003
const char win_xp_string[] = "Microsoft Windows XP";
下面判断是否
XP
系统。
#004
BOOL is_win_xp = ( getOSInfo().getOSString().substr(0, strlen(win_xp_string) ) == win_xp_string ); /* Flawfinder: ignore*/
#005
if( is_win_xp )
#006
{
#007
// Note: we need to use run-time dynamic linking, because load-time dynamic linking will fail
#008
// on systems that don't have the library installed (all non-Windows XP systems)
是XP系统,就加载异常报告的动态连接库faultrep.dll。
#009
HINSTANCE fault_rep_dll_handle = LoadLibrary(L"faultrep.dll"); /* Flawfinder: ignore */
#010
if( fault_rep_dll_handle )
#011
{
获取函数AddERExcludedApplicationA来设置一个程序不要产生异常报告。
#012
pfn_ADDEREXCLUDEDAPPLICATIONA pAddERExcludedApplicationA = (pfn_ADDEREXCLUDEDAPPLICATIONA) GetProcAddress
#013 (fault_rep_dll_handle, "AddERExcludedApplicationA");
#014
if( pAddERExcludedApplicationA )
#015
{
#016
#017
// Strip the path off the name
下面获取应用程序的名称,然后设置程序不产生异常报告。
#018
const char* executable_name = gDirUtilp->getExecutableFilename().c_str();
#019
#020
if( 0 == pAddERExcludedApplicationA( executable_name ) )
#021
{
#022
U32 error_code = GetLastError();
#023
llinfos << "AddERExcludedApplication() failed with error code " << error_code << llendl;
#024
}
#025
else
#026
{
#027
llinfos << "AddERExcludedApplication() success for " << executable_name << llendl;
#028
}
#029
}
释放动态连接。
#030
FreeLibrary( fault_rep_dll_handle );
#031
}
#032
}
#033 }
通过这个函数的设置,就可以修改第二人生程序产生异常时,并不产生XP的异常报告,只会生成第二生自己的错误报告,并发送到自己的服务器上。