Basically, everything is inside '<winerror.h>'. But, I have this feeling, that might be not a popular answer.
The Context
HRESULT is a handle (value of type long) returned from Win32, COM and other functions in the vast ocean of Windows SDK. What and how is packed in that handle is explained in <winerror.h>
I might dare to think there is one fact about Win32 of great use to C++ developers.
Win32 is written in C
Thus there are no C++ exceptions. Ditto HRESULT is your friend. There are "special exceptions" called SEH (Structured Exceptions Handling). And they are "inbuilt" into the Windows. Even MS STL uses SEH when c++ exceptions are switched off (gasp!). But that was not part of the question.
The usage looks very simple:
HRESULT hr ;
ULONG ansi_size_ ;
hr = DiscpUnicodeToAnsiSize(L"Look Ma, I am doing WIN32!", &ansi_size_ );
if ( FAILED(hr) ) {
// there was some error
// what exactly has happened?
HRESULT facility = HRESULT_FACILITY(hr);
HRESULT severity = HRESULT_SEVERITY(hr);
// we can for example look for a particular facility
if ( facility == FACILITY_MSMQ)
{
// hey, just what is MSMQ ?!
// let see the code part
HRESULT code = HRESULT_CODE(hr);
}
}
<winerror.h>
is (currently) 62238 lines long. Feel free to browse it and you will find a lot of useful nuggets.
Wikipedia article on HRESULT is actually short and to the point.
Win32 is now several decades old. Inevitably there are dusty corners. But HRESULT will stay "forever" and in active development.
As it happens Windows Error Codes Protocol Revision 20 (gasp) has been released just yesterday!
But that is C!?
There have been few official projects (also released) to "encapsulate" HRESULT and COM into C++ types. MFC, ATL ... My favourite is Compiler COM Support, and in particular, the _com_error class.
I hope this has helped ...