Windows / HRESULT
HRESULT
HRESULT codes are used under the COM system.
The table below denotes the structure of a HRESULT code.
1 | 3 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 2 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 1 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
S | R | C | N | X | Facility | Code |
Legend
- S (1 bit): Severity. If set, indicates a failure result. If clear, indicates a success result.
- R (1 bit): Reserved. This bit must be cleared.
- C (1 bit): Customer. Set for customer-defined values. All Microsoft values have this bit cleared.
- N (1 bit): NTSTATUS if set.
- X (1 bit): Reserved. Should be cleared, at the exception of a few codes described further below.
- Facility (11 bits): Error source. A list of facilities are listed further below.
- Code (16 bits): Error code.
Facilities
The table below lists facilities defined in the MS-ERREF specification.
Name | Value | Description |
---|---|---|
FACILITY_NULL | 0 | Default |
FACILITY_RPC | 1 | RPC subsystem |
FACILITY_DISPATCH | 2 | COM Dispatch |
FACILITY_STORAGE | 3 | OLE Storage |
FACILITY_ITF | 4 | COM/OLE Interface management |
FACILITY_WIN32 | 7 | Win32 |
FACILITY_WINDOWS | 8 | Windows |
FACILITY_SECURITY | 9 | Security API |
FACILITY_CONTROL | 10 | Control mechanism |
FACILITY_CERT | 11 | Certificate |
FACILITY_INTERNET | 12 | Wininet |
FACILITY_MEDIASERVER | 13 | Windows Media Server |
FACILITY_MSMQ | 14 | Microsoft Message Queue |
FACILITY_SETUPAPI | 15 | Setup API |
FACILITY_SCARD | 16 | Smart-card subsystem |
FACILITY_COMPLUS | 17 | COM+ |
FACILITY_AAF | 18 | Microsoft agent |
FACILITY_URT | 19 | .NET CLR |
FACILITY_ACS | 20 | Audit Collection Service |
FACILITY_DPLAY | 21 | Direct Play |
FACILITY_UMI | 22 | Ubiquitous Memory-introspection service |
FACILITY_SXS | 23 | Side-by-side (sxs) servicing |
FACILITY_WINDOWS_CE | 24 | Windows CE |
FACILITY_HTTP | 25 | HTTP |
FACILITY_USERMODE_COMMONLOG | 26 | Common Logging |
FACILITY_USERMODE_FILTER_MANAGER | 31 | User Mode Filter Manager |
FACILITY_BACKGROUNDCOPY | 32 | Background Copy |
FACILITY_CONFIGURATION | 33 | Configuration Services |
FACILITY_STATE_MANAGEMENT | 34 | State Management Services |
FACILITY_METADIRECTORY | 35 | Microsoft Identity Server |
FACILITY_WINDOWSUPDATE | 36 | Windows update |
FACILITY_DIRECTORYSERVICE | 37 | Active Directory |
FACILITY_GRAPHICS | 38 | Graphics drivers |
FACILITY_SHELL | 39 | User shell |
FACILITY_TPM_SERVICES | 40 | Trusted Platform Module services |
FACILITY_TPM_SOFTWARE | 41 | Trusted Platform Module applications |
FACILITY_PLA | 48 | Performance Logs and Alerts |
FACILITY_FVE | 49 | Full Volume Encryption |
FACILITY_FWP | 50 | Firewall Platform |
FACILITY_WINRM | 51 | Windows Resource Manager |
FACILITY_NDIS | 52 | Network Driver Interface |
FACILITY_USERMODE_HYPERVISOR | 53 | Usermode Hypervisor components |
FACILITY_CMI | 54 | Configuration Management Infrastructure |
FACILITY_USERMODE_VIRTUALIZATION | 55 | User Mode Virtualization Subsystem |
FACILITY_USERMODE_VOLMGR | 56 | User Mode Volume Manager |
FACILITY_BCD | 57 | Boot Configuration Database |
FACILITY_USERMODE_VHD | 58 | User Mode Virtual Hard Disk |
FACILITY_SDIAG | 60 | System Diagnostics |
FACILITY_WEBSERVICES | 61 | Web Services |
FACILITY_WINDOWS_DEFENDER | 80 | Windows Defender |
FACILITY_OPC | 81 | Open Connectivity service |
Exceptions to the X Bit
Some HRESULT codes, as exceptions, have the X bit set. They are listed below.
Value | Name |
---|---|
0x0DEAD100 | TRK_S_OUT_OF_SYNC |
0x0DEAD102 | TRK_VOLUME_NOT_FOUND |
0x0DEAD103 | TRK_VOLUME_NOT_OWNED |
0x0DEAD107 | TRK_S_NOTIFICATION_QUOTA_EXCEEDED |
0x8DEAD01B | TRK_E_NOT_FOUND |
0x8DEAD01C | TRK_E_VOLUME_QUOTA_EXCEEDED |
0x8DEAD01E | TRK_SERVER_TOO_BUSY |
Converting Win32 Codes to HRESULT
Converting Win32 error codes to an HRESULT code is done with the following C macro.
#define FACILITY_WIN32 0x0007 #define __HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)))