COM Error---HRESULT
一、COM Error
调用COM接口产生的错误。几乎所有的COM函数和接口方法都返回类型为HRESULT的值。HRESULT(用于结果句柄)是返回成功、警告和错误值的一种方法。HRESULTs实际上不是任何事物的句柄;它们只是值中有几个字段编码的值。根据COM规范,结果为零表示成功,非零表示失败。
二、COM Error Code(HRESULT)
也是一个32bit的值,大多数的值也是定义了默认的错误消息。它的构成如下

S (1 bit):严重程度,1为失败,0为成功
R (1 bit): 如果N=0,必须设置为1,N=0,该位被NTSTATUS定义
C (1 bit): 是否是客户定义,还是微软定义的错误.1是客户定制
N (1 bit): 标识是否是一个NTSTATUS的值,0的话可以把NTSTATUS值映射为一个HRESULT值
X (1 bit): 保留位,永远是0
Facility (11 bits):错误来源,取值如下
|
Value |
Meaning |
|---|---|
|
FACILITY_NULL 0 |
The default facility code. |
|
FACILITY_RPC 1 |
The source of the error code is an RPC subsystem. |
|
FACILITY_DISPATCH 2 |
The source of the error code is a COM Dispatch. |
|
FACILITY_STORAGE 3 |
The source of the error code is OLE Storage. |
|
FACILITY_ITF 4 |
The source of the error code is COM/OLE Interface management. |
|
FACILITY_WIN32 7 |
This region is reserved to map undecorated error codes into HRESULTs. |
|
FACILITY_WINDOWS 8 |
The source of the error code is the Windows subsystem. |
|
FACILITY_SECURITY 9 |
The source of the error code is the Security API layer. |
|
FACILITY_SSPI 9 |
The source of the error code is the Security API layer. |
|
FACILITY_CONTROL 10 |
The source of the error code is the control mechanism. |
|
FACILITY_CERT 11 |
The source of the error code is a certificate client or server? |
|
FACILITY_INTERNET 12 |
The source of the error code is Wininet related. |
|
FACILITY_MEDIASERVER 13 |
The source of the error code is the Windows Media Server. |
|
FACILITY_MSMQ 14 |
The source of the error code is the Microsoft Message Queue. |
|
FACILITY_SETUPAPI 15 |
The source of the error code is the Setup API. |
|
FACILITY_SCARD 16 |
The source of the error code is the Smart-card subsystem. |
|
FACILITY_COMPLUS 17 |
The source of the error code is COM+. |
|
FACILITY_AAF 18 |
The source of the error code is the Microsoft agent. |
|
FACILITY_URT 19 |
The source of the error code is .NET CLR. |
|
FACILITY_ACS 20 |
The source of the error code is the audit collection service. |
|
FACILITY_DPLAY 21 |
The source of the error code is Direct Play. |
|
FACILITY_UMI 22 |
The source of the error code is the ubiquitous memoryintrospection service. |
|
FACILITY_SXS 23 |
The source of the error code is Side-by-side servicing. |
|
FACILITY_WINDOWS_CE 24 |
The error code is specific to Windows CE. |
|
FACILITY_HTTP 25 |
The source of the error code is HTTP support. |
|
FACILITY_USERMODE_COMMONLOG 26 |
The source of the error code is common Logging support. |
|
FACILITY_USERMODE_FILTER_MANAGER 31 |
The source of the error code is the user mode filter manager. |
|
FACILITY_BACKGROUNDCOPY 32 |
The source of the error code is background copy control |
|
FACILITY_CONFIGURATION 33 |
The source of the error code is configuration services. |
|
FACILITY_STATE_MANAGEMENT 34 |
The source of the error code is state management services. |
|
FACILITY_METADIRECTORY 35 |
The source of the error code is the Microsoft Identity Server. |
|
FACILITY_WINDOWSUPDATE 36 |
The source of the error code is a Windows update. |
|
FACILITY_DIRECTORYSERVICE 37 |
The source of the error code is Active Directory. |
|
FACILITY_GRAPHICS 38 |
The source of the error code is the graphics drivers. |
|
FACILITY_SHELL 39 |
The source of the error code is the user Shell. |
|
FACILITY_TPM_SERVICES 40 |
The source of the error code is the Trusted Platform Module services. |
|
FACILITY_TPM_SOFTWARE 41 |
The source of the error code is the Trusted Platform Module applications. |
|
FACILITY_PLA 48 |
The source of the error code is Performance Logs and Alerts |
|
FACILITY_FVE 49 |
The source of the error code is Full volume encryption. |
|
FACILITY_FWP 50 |
he source of the error code is the Firewall Platform. |
|
FACILITY_WINRM 51 |
The source of the error code is the Windows Resource Manager. |
|
FACILITY_NDIS 52 |
The source of the error code is the Network Driver Interface. |
|
FACILITY_USERMODE_HYPERVISOR 53 |
The source of the error code is the Usermode Hypervisor components. |
|
FACILITY_CMI 54 |
The source of the error code is the Configuration Management Infrastructure. |
|
FACILITY_USERMODE_VIRTUALIZATION 55 |
The source of the error code is the user mode virtualization subsystem. |
|
FACILITY_USERMODE_VOLMGR 56 |
The source of the error code is the user mode volume manager |
|
FACILITY_BCD 57 |
The source of the error code is the Boot Configuration Database. |
|
FACILITY_USERMODE_VHD 58 |
The source of the error code is user mode virtual hard disk support. |
|
FACILITY_SDIAG 60 |
The source of the error code is System Diagnostics. |
|
FACILITY_WEBSERVICES 61 |
The source of the error code is the Web Services. |
|
FACILITY_WINDOWS_DEFENDER 80 |
The source of the error code is a Windows Defender component. |
|
FACILITY_OPC 81 |
The source of the error code is the open connectivity service. |
Code (2 bytes): 结果码,有一部分值是从Win32 Error Code和NTSTATUS继承来的。
在源代码级别,所有错误值都由三部分组成,由下划线分隔。第一部分是识别与错误相关联的设施的前缀,第二部分是E表示错误,第三部分是描述实际情况的字符串。例如,当硬盘上没有剩余空间时,会返回STG_E_MEDIUMFULL。stg前缀表示存储设备,e表示状态代码表示错误,MEDIUMFULL提供有关错误的特定信息。
三、HRESULT
3.1、HRESULT的定义
在头文件winnt.h里,HRESULT定义如下:
// Component Object Model defines, and macros
#ifndef _HRESULT_DEFINED
#define _HRESULT_DEFINED
typedef LONG HRESULT;
#endif // !_HRESULT_DEFINED
值就是COM Error Code。
3.2、获取和检测
从定义可以看到 HRESULT被定义为了LONG型,也就是把COM Error Code当成一个4字节的有符号数来处理,这样一来就可以把Error Code的最高位S当成符号位,0时是正数,1时是负数,当我们调用COM接口,就可以用下面的宏来检测COM接口的返回值
#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
#define FAILED(Status) ((HRESULT)(Status) <0)
成功的代码有多个,失败的代码也有多个,一个COM接口在各种情况下返回的状态代码通常将包含多个成功代码及多个失败代码。这就是我们为什么要使用SUCCEEDED及FAILED宏的原因。一般不能直接将HRESULT值同某个成功代码(如S_OK)进行比较以决定某个函数是否成功。
3.3、获取错误消息
也是通过这个函数来获取
DWORD WINAPI FormatMessage ( DWORD dwFlags, // source and processing options LPCVOID lpSource, // message source DWORD dwMessageId, // message identifier DWORD dwLanguageId, // language identifier LPTSTR lpBuffer, // message buffer DWORD nSize, // maximum size of message buffer va_list *Arguments // array of message inserts );COM Error---HRESULT的更多相关文章
- WP8异常错误:Error HRESULT E_FAIL has been returned from a call to a COM component.
在做WP8开发的过程中,使用到了longlistselector这个控件,本来使用没有问题. 但是突然出现了一个闪退的错误,错误信息如下: {MS.Internal.WrappedException: ...
- ArcGIS “Error HRESULT E_FAIL has been returned from a call to a COM component.” 异常的解决
错误提示内容: {System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been ret ...
- OPC-System.Runtime.InteropServices.COMException:“Error HRESULT E_FAIL has been returned from a call to a COM component.”
Error HRESULT E_FAIL has been returned from a call to a COM component的错误提示,还是因为OPC配置,这次是红框中标签定义错误,应该 ...
- Win7下VS2010使用“ASP.Net 3.5 Claims-aware Template”创建ClaimsAwareWebSite报"HRESULT: 0x80041FEB"错误的解决办法
问题描述: 使用VS2010的WIF开发模板创建“Claims-aware ASP.NET Site”.“Claims-aware WCF Service”,下载安装后,创建网站时,报错"H ...
- 【ArcGIS二次开发】CreateFeature报错(HRESULT E_FAIL)
在VS2010下基于ArcGIS 10.1做二次开发时遇到个奇怪的问题,对于MXD工程文档中已经存在的图层,获取其FeatureClass可以调用CreateFeature()函数生成要素,但是对于通 ...
- MSXML读取XML中文
// QueryNodes.cpp : Defines the entry point for the console application. // #include <stdio.h> ...
- AE错误代码解释
每当我们在进行AE开发,出现错误时经常会出现错误代码,但是我们并不知道它到底代表什么意思,这里的而错误编码我们可以对照着找到我们需要的时候常详细信息(问题是,经常还是会出现没有错误编码HRESULT ...
- 使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题
原文 使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题 虽然微软宣称 Windows 10 将是最后一个 Windows 版本,但由于年代跨越 ...
- 基于第三方开源库的OPC服务器开发指南(3)——OPC客户端
本篇将讲解如何编写一个OPC客户端程序测试我们在前文<基于第三方开源库的OPC服务器开发指南(2)——LightOPC的编译及部署>一篇建立的服务器.本指南的目的是熟悉OPC服务器的开发流 ...
- 解决:安装SQL Server 2008 Native Client遇到错误(在Navicat premium新建sqlserver连接时 需要):An error occurred during ...HRESULT: 0x80070422(注意尾部的错误号)
解决:安装SQL Server 2008 Native Client遇到错误(在Navicat premium新建sqlserver连接时 需要):An error occurred during . ...
随机推荐
- centos jira wiki 开机自启
启动jira 和 wiki 需要java环境变量 操作步骤: 在 /etc/rc.d/rc.local 文件中[ 注意要有可执行权限 ] export JAVA_HOME=xxxxxxxx expor ...
- 【SQL Server数据迁移】64位的机器:SQL Server中查询ORACLE的数据
从SQL Server中查询ORACLE中的数据,可以在SQL Server中创建到ORACLE的链接服务器来实现的,但是根据32位 .64位的机器和软件, 需要用不同的驱动程序来实现. 在64位的机 ...
- Hadoop2-认识Hadoop大数据处理架构-单机部署
一.Hadoop原理介绍 1.请参考原理篇:Hadoop1-认识Hadoop大数据处理架构 二.centos7单机部署hadoop 前期准备 1.创建用户 [root@web3 ~]# useradd ...
- CCF 2016-04-2 俄罗斯方块
CCF 2016-04-2 俄罗斯方块 题目 问题描述 俄罗斯方块是俄罗斯人阿列克谢·帕基特诺夫发明的一款休闲游戏. 游戏在一个15行10列的方格图上进行,方格图上的每一个格子可能已经放置了方块,或者 ...
- Celery定时任务细讲
Celery定时任务细讲 一.目录结构 任务所在目录 ├── celery_task # celery包 如果celery_task只是建了普通文件夹__init__可以没有,如果是包一定要有 │ ├ ...
- elasticsearch*3 + Es-Head + kibana Docker集群
ES官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html 拉取docker镜像 dock ...
- 【洛谷 P2597】 [ZJOI2012]灾难(LCA)
题目链接 考虑建一棵树,使一个生物灭绝时他的子树都会灭绝,显然这样答案就是以每个点为根的子树大小-1. 为什么原图不是一棵树,因为一个生物可能会以多个生物为食,所以按拓扑序来建树,把每个遍历到的点的父 ...
- dubbo源码阅读之服务目录
服务目录 服务目录对应的接口是Directory,这个接口里主要的方法是 List<Invoker<T>> list(Invocation invocation) throws ...
- Ajax + PHP 的用法以及遇见的问题
由于自己是个php小白,所以新知识点都要自己去不断的试验和摸索. 分享下自己用php + ajax交互的用法和问题. 前端代码: $.ajax({ type: "POST", da ...
- 智慧图携手DataPipeline,让实体商业更智慧!
近日,国内领先的实体商业数字化运营服务商智慧图携手DataPipeline,基于专业的数据集成与应用基础展开了合作. 未来DataPipeline将通过不断提升自身产品和服务实力,与智慧图一道致力于帮 ...