MtVerify.h 头文件内容,用的时候添加到工程就行了
2012-08-07 14:49
267 查看
/** * MtVerify.h * * Error handling for applications in * "Multitheading Applications in Win32" * * The function PrintError() is marked as __inline so that it can be * included from one or more C or C++ files without multiple definition * errors. For the examples in this book, this works fine. * To use the PrintError() in an application, it should be taken out, * placed in its own source file, and the "__inline" declaration removed * so the function will be globally available. */ #pragma comment( lib, "USER32" ) #include <stdlib.h> #include <crtdbg.h> #define MTASSERT(a) _ASSERTE(a) // 宏定义 __FILE__ 与__LINE__都是预处理符号提供错误信息的描述 // 如果a返回FALSE就执行PrintError函数 #define MTVERIFY(a) if (!(a)) PrintError(#a,__FILE__,__LINE__,GetLastError()) __inline void PrintError(LPSTR linedesc, LPSTR filename, int lineno, DWORD errnum) { LPSTR lpBuffer; char errbuf[256]; #ifdef _WINDOWS char modulename[MAX_PATH]; #else // _WINDOWS DWORD numread; #endif // _WINDOWS // 把从GetLastError()返回的错误码转化为错误信息 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, errnum, LANG_NEUTRAL, (LPTSTR)&lpBuffer, 0, NULL ); wsprintfA(errbuf, "/nThe following call failed at line %d in %s:/n/n" " %s/n/nReason: %s/n", lineno, filename, linedesc, lpBuffer); // 如果是console程序就输出信息到控制台上 #ifndef _WINDOWS WriteFile(GetStdHandle(STD_ERROR_HANDLE), errbuf, strlen(errbuf), &numread, FALSE ); // 等待3秒钟是为了使用者看到出错信息 Sleep(3000); // 如果是窗口程序就一弹出对话框的形式输出错误信息 #else // 当前exe文件的全路径 GetModuleFileName(NULL, modulename, MAX_PATH); // 置弹出窗口在最上层以免被忽略 MessageBox(NULL, errbuf, modulename, MB_ICONWARNING|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND); #endif // 把结束代码EXIT_FAILURE 交给操作系统 exit(EXIT_FAILURE); }
相关文章推荐
- MtVerify.h 头文件内容,用的时候添加到工程就行了
- log4j添加日志一定记住在工程的web.xml文件下加一些内容
- 如何在Eclipse中添加新建包,java文件,工程工具栏按钮
- iOS项目工程添加.a文件遇到的Dsymutil Error
- 如何读取工程中的一个文件内容
- 向ramdisk类的镜像文件中添加内容
- 解决合并文件内容因vim自动添加换行问题
- . <WP7>读取工程中的一个文件内容
- 在linux下批量向文件末尾添加内容
- shell如何在指定文件的指定位置后面添加内容
- 如何解决Visual c++不能打开文件以及工程不能添加文件的问题(转)
- 私用:hosts文件额外添加的内容
- VC++6.0打开文件和添加文件到工程时出错
- git blame 可以查看文件中的某一行内容是在哪个commit id号添加的
- java中实现,在大文件的第一行添加内容
- android读取工程根目录下文件内容
- VC6.0打开或者添加工程文件崩溃的解决方法
- java读取工程配置文件内容
- 给pdf文件添加防伪水印logo(附工程源码下载)
- shell脚本,在不同目录下新建同名文件,并添加内容