第二人生的源码分析(三十九)关闭WinXP的错误报告功能

在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的异常报告,只会生成第二生自己的错误报告,并发送到自己的服务器上。
 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值