HRESULT
From Wikipedia, the free encyclopedia
The introduction to this article provides insufficient context for those unfamiliar with the subject. Please help improve the article with a good introductory style. |
HRESULT is the data type used to indicate the status of operations in Microsoft's components. An HRESULT value has 32 bits divided into three fields: a severity code, a facility code, and an error code. The severity code indicates whether the return value represents information, warning, or error. The facility code identifies the area of the system responsible for the error. The error code is a unique number that is assigned to represent the exception. Each exception is mapped to a distinct HRESULT. When managed code throws an exception, the runtime passes the HRESULT to the COM client. When unmanaged code returns an error, the HRESULT is converted to an exception, which is then thrown by the runtime. HRESULTs are 32 bit values laid out as follows:
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 +-+-+-+-+-+---------------------+-------------------------------+ |S|R|C|N|r| Facility | Code | +-+-+-+-+-+---------------------+-------------------------------+
[edit] Details
All values are represented as hexidecimal values.
- S - Severity - indicates success/fail
- 0 - Success
- 8 - Failure
- C - Severe Failure
- R - reserved portion of the facility code, corresponds to NT's second severity bit.
- C - reserved portion of the facility code, corresponds to NT's C field.
- N - reserved portion of the facility code. Used to indicate a mapped NT status value.
- r - reserved portion of the facility code. Reserved for internal use. Used to indicate HRESULT values that are not status values, but are instead message ids for display strings.
- Facility - is the facility code
- 1 - RPC
- 2 - Dispatch
- 3 - Storage
- 4 - ITF
- 5 -
- 6 -
- 7 - Win32
- 8 - Windows
- 9 - SSPI
- 10 - SCARD
- 11 - COMPLUS
- 12 - AAF
- 13 - URT
- 14 - ACS
- 15 - DPLAY
- 16 - UMI
- 17 - SXS
- 18 - WINDOWS CE
- 19 - HTTP
- 20 - BACKGROUNDCOPY
- 21 - CONFIGURATION
- 22 - STATE MANAGEMENT
- 23 - META DIRECTORY
- 24 - WINDOWS UPDATE
- 25 - DIRECTORY SERVICE
- 26 - GRAPHICS
- 27 - SHELL
- 28 - TPM SERVICES
- 29 - TPM SOFTWARE
- 30 - PLA
- 31 - FVE
- 32 - FWP
- 33 - WINRM
- Code - is the facility's status code
[edit] Examples
- 0x80070005
- 8 - Failure
- 7 - Win32
- 5 - "Access Denied"
- 0x80090032
- 8 - Failure
- 9 - SSPI
- 32 - "The request is not supported"
These values are defined in the corresponding header (.h) files with the Microsoft Windows Platforms SDK or DDK. You can use a tool called ERR.EXE to take the value and translate it to the corresponding error string.
[edit] External links
- Microsoft Open Protocol Specification - HRESULT Values
- Microsoft Developer Network Reference
- Windows Data Types
- Using Macros for Error Handling
An opaque result handle defined to be zero for a successful return from a function and nonzero if error or status information is returned. To obtain the Code part of an HRESULT, use the HRESULT_CODE() macro.
To check if a call that returns an HRESULT succeeded, make sure the S field is 0 (i.e. the number is non-negative) or use the SUCCEEDED() macro.