由 错误号 得到 错误字符串
2011-09-22 15:38
148 查看
FormatMessageA(//FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0,//Default language lpErrMsgBuf, 100, NULL); printf("Fail Starting the Service. Error %ld: %s",GetLastError(),lpErrMsgBuf); LocalFree(lpErrMsgBuf);
更可以编成宏:
#define PRINT_ERR(x, err) {\ char lpErrMsgBuf_75367[101]={0};\ int errNum_25456 = err;\ FormatMessageA(\ FORMAT_MESSAGE_FROM_SYSTEM|\ FORMAT_MESSAGE_IGNORE_INSERTS,\ NULL,\ errNum_25456,\ 0,/*Default language*/\ lpErrMsgBuf_75367,\ 100,\ NULL);\ printf(x, errNum_25456, lpErrMsgBuf_75367);}
调用时使用 PRINT_ERR("xxxxxxxx failed! Error %d : %s\n", GetLastError());
现在发现,为何不用CException类呢
TRY { DoDataExchange(&dx); bOK = TRUE; // it worked } CATCH(CUserException, e) { // validation failed - user already alerted, fall through ASSERT(!bOK); // Note: DELETE_EXCEPTION_(e) not required } AND_CATCH_ALL(e) { // validation failed due to OOM or other resource failure e->ReportError(MB_ICONEXCLAMATION, AFX_IDP_INTERNAL_FAILURE); ASSERT(!bOK); DELETE_EXCEPTION(e); } END_CATCH_ALL
相关文章推荐
- 由GetLastError()获得的错误代码得到字符串描述
- 由GetLastError()获得的错误代码得到字符串描述
- 由GetLastError()获得的错误代码得到字符串描述
- HTTP 错误 404.15 - Not Found 请求筛选模块被配置为拒绝包含的查询字符串过长的请求。
- 从错误中得知--关于字符串我以前没注意的东西
- 得到字符串日期的下一日
- 给定俩个字符串一个S(母串),一个T(子串),有多少种方法从母串中移除字符得到子字符串
- 星外虚拟主机管理平台 开通数据库 出现Microsoft OLE DB Provider for SQL Server 错误 '8004' 从字符串向 datetime 转换失败
- 关于网上搜查得到的3DC3的基于字符串后缀数组的排序方法的怀疑
- Oracle ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小
- 得到网卡MAC地址 去除字符串前后所有空格
- 求最大公共字符串----发现书上的错误了
- 20180204.ajax提交注册数据;axios跨域请求得到json字符串;实现注册功能
- 利用Random得到随机数字、字母和字符串
- 关于错误“将截断字符串或二进制数据。 语句已终止”
- ora-01830错误:日期格式图片在转换整个输入字符串之前结束
- WWW解析Json字符串错误
- 每天一道算法题(29)——检测字符串的是否由移位得到
- 相当无聊之Delphi截取字符串123-456-7,得到123,456,7
- 得到指定字符串列表中,指定个数的字符串