HRESULT is a computer programming data type that represents the completion status of a function.
[citation needed] An HRESULT is designed to simultaneously be both a simple numerical value and a structure of fields indicating severity, facility and status code.
Use of HRESULT is most commonly encountered in COM programming, where it forms the basis for a standardized error handling mechanism, but its use is not limited to COM.
Examples:[3] Sometimes an HRESULT value is shown as a signed integer, but this is less common and harder to read.
An HRESULT is sometimes represented as an identifier with the format Facility_Severity_Reason:[4] For example, STG_E_FILENOTFOUND indicates a storage related error, file does not exist.
This representation is easier to read than a numerical format but is less precise since although based on convention there is no definitive algorithm to convert between value and name.
The HRESULT was originally defined in the IBM/Microsoft OS/2 operating system as a general-purpose error return code, and subsequently adopted in Windows NT.
Older Windows APIs tend to not support it at all, returning HRESULTs without any IErrorInfo data.
More modern Windows COM subsystems often provide extensive error information in the message description of the IErrorInfo object.
The COM team decided that the cost/benefit simply wasn’t worth it, so the HRESULT turned into a simple number.