MtVerify.h 头文件内容,用的时候添加到工程就行了

  1. /**   
  2. * MtVerify.h   
  3. *   
  4. * Error handling for applications in   
  5. * "Multitheading Applications in Win32"   
  6. *   
  7. * The function PrintError() is marked as __inline so that it can be   
  8. * included from one or more C or C++ files without multiple definition   
  9. * errors. For the examples in this book, this works fine.   
  10. * To use the PrintError() in an application, it should be taken out,   
  11. * placed in its own source file, and the "__inline" declaration removed   
  12. * so the function will be globally available.   
  13. */    
  14. #pragma comment( lib, "USER32" )     
  15. #include <stdlib.h>     
  16. #include <crtdbg.h>     
  17. #define MTASSERT(a) _ASSERTE(a)     
  18. // 宏定义 __FILE__ 与__LINE__都是预处理符号提供错误信息的描述     
  19. // 如果a返回FALSE就执行PrintError函数     
  20. #define MTVERIFY(a) if (!(a)) PrintError(#a,__FILE__,__LINE__,GetLastError())     
  21. __inline void PrintError(LPSTR linedesc, LPSTR filename, int lineno, DWORD errnum)     
  22. {     
  23.     LPSTR lpBuffer;     
  24.     char errbuf[256];     
  25. #ifdef _WINDOWS     
  26.     char modulename[MAX_PATH];     
  27. #else // _WINDOWS     
  28.     DWORD numread;     
  29. #endif // _WINDOWS     
  30.     // 把从GetLastError()返回的错误码转化为错误信息      
  31.     FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER     
  32.         | FORMAT_MESSAGE_FROM_SYSTEM,     
  33.         NULL,     
  34.         errnum,     
  35.         LANG_NEUTRAL,     
  36.         (LPTSTR)&lpBuffer,     
  37.         0,     
  38.         NULL );     
  39.     wsprintfA(errbuf, "/nThe following call failed at line %d in %s:/n/n"    
  40.         " %s/n/nReason: %s/n", lineno, filename, linedesc, lpBuffer);     
  41.     // 如果是console程序就输出信息到控制台上  
  42. #ifndef _WINDOWS     
  43.     WriteFile(GetStdHandle(STD_ERROR_HANDLE), errbuf, strlen(errbuf), &numread, FALSE );     
  44.     // 等待3秒钟是为了使用者看到出错信息     
  45.     Sleep(3000);     
  46.     // 如果是窗口程序就一弹出对话框的形式输出错误信息  
  47. #else     
  48.     // 当前exe文件的全路径     
  49.     GetModuleFileName(NULL, modulename, MAX_PATH);     
  50.     // 置弹出窗口在最上层以免被忽略     
  51.     MessageBox(NULL, errbuf, modulename, MB_ICONWARNING|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);     
  52. #endif     
  53.     // 把结束代码EXIT_FAILURE 交给操作系统  
  54.     exit(EXIT_FAILURE);     
  55. }   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值