Structure of COM Error Codes

The following illustration shows the format of an HRESULT (or SCODE); the numbers indicate bit positions:

Shows the format of an 'H RESULT' or 'S CODE' with numbers indicating bit positions.

The high-order bit in the HRESULT or SCODE indicates whether the return value represents success or failure. If set to 0, SEVERITY_SUCCESS, the value indicates success. If set to 1, SEVERITY_ERROR, it indicates failure.

The R, C, N, and r bits are reserved.

The facility field indicates the system service responsible for the error. Microsoft allocates new facility codes as they become necessary. Most SCODEs and HRESULT values set the facility field to FACILITY_ITF, indicating an interface method error.

Common facility fields are described in the following table.

SymbolicCodeDescription
FACILITY_DISPATCH2For late-binding IDispatch interface errors.
FACILITY_ITF4For most status codes returned from interface methods. The actual meaning of the error is defined by the interface. That is, two HRESULT s with exactly the same 32-bit value returned from two different interfaces might have different meanings.
FACILITY_NULL0For broadly applicable common status codes such as S_OK.
FACILITY_RPC1For status codes returned from remote procedure calls.
FACILITY_STORAGE3For status codes returned from IStorage or IStream method calls relating to structured storage. Status codes whose code (lower 16 bits) value is in the range of MS-DOS error codes (that is, less than 256) have the same meaning as the corresponding MS-DOS error.
FACILITY_WIN327Used to provide a means of handling error codes from functions in the Windows API as an HRESULT . Error codes in 16-bit OLE that duplicated system error codes have also been changed to FACILITY_WIN32.
FACILITY_WINDOWS8Used for additional error codes from Microsoft-defined interfaces.
7 entries

Article text from the Win32 documentation (opens in a new tab), by Microsoft, under the CC BY 4.0 (opens in a new tab) licence.