HRESULT 数据类型和显示错误信息
来源:互联网 发布:土豪金手机淘宝 编辑:程序博客网 时间:2024/06/07 01:23
HRESULT
What we should know about HRESULT ?
- HRSULT is a kind of Data Type ( Long 32bit) which is used for Windows.
- It is The return codes used by COM interfaces.
- To test an HRESULT value, use the FAILED and SUCCESSED macros.
- This type is declared in WinNT.h as follows:
typedef LONG HRESULT;
Structure of COM Error Codes.
- HRESULT value has 32bits and is divided into 3 fields: a severity code, a facility code, and an error code.
Bit 31 30 29 28 27, 26 25 24 ... 16, 15 14 ... 0
Field S R C N r , Facility , Error
Convert HRSULT retrun codes to error messages.
法(1) We can use AMGetErrorText Function.
- Syntax :
DWORD AMGetErrorText (HRESULT hr, // HRESULT value.
TCHAR *pBuffer, // Pointer to a character buffer that receives the error message. DWORD MaxLen // Number of characters in pBuffer.);
- Requirement:
Header: Errors.h (dshow.h)
Lib : Quarz.lib
- Example:
void ShowError(HRESULT hr){ if (FAILED(hr)) { TCHAR szErr[MAX_ERROR_TEXT_LEN]; DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN); if (res == 0) { StringCchPrintf(szErr, MAX_ERROR_TEXT_LEN, "Unknown Error: 0x%2x", hr); } MessageBox(0, szErr, TEXT("Error!"), MB_OK | MB_ICONERROR); }}
//But , 我尝试上述,似乎总是找不到AMGetErrorText函数,找不到合适的H文件,可能需要安装额外的SDK.
法 (2)
CString HrToMessage( HRESULT hr ){ LPVOID lpMsgBuf; CString strTmp; ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); strTmp.Format( _T("%s"), (char *) lpMsgBuf ); ::LocalFree( lpMsgBuf ); return strTmp;}
- HRESULT 数据类型和显示错误信息
- 显示错误信息
- 显示错误信息
- 显示错误信息
- RatingBar的使用和显示错误信息
- PHP.ini 设置PHP错误信息(errors)的屏蔽和显示
- 关于华为无法显示调试信息和错误信息
- 关于错误信息的显示
- 不显示脚本错误信息
- 显示服务器端详细错误信息
- ASP 显示完整错误信息
- 如何:显示安全错误信息
- sharepoint显示详细错误信息
- struts2错误信息显示
- web前台显示错误信息
- php显示错误信息
- ASP显示页面错误信息
- php如何显示错误信息
- python 参数列表中的self 显式不等于冗余
- strut1简介
- poj 2677 双调欧几里得旅行商问题
- 【每日一题】2012.6.6:判断JollyJumper序列
- 常用输出JS脚本的类[C#源码]
- HRESULT 数据类型和显示错误信息
- CCSPrite Class Reference(CCSprite 类参考手册)
- 又是一年高考季(2012高考前的一些随想)
- 获取控制台窗口的句柄
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关 2
- checkbox选中判断及实现单选功能
- 合车出去游玩事项
- WSUS 客户端状态尚未报告
- 数据库基本命令的总结