I'd like to be able to do the equivalent of FormatMessage - generate a text message for debug and even runtime builds that can report some of the common HRESULTs, or even spit out things like what the severity is, what facility it was, and possibly a description of the error code.
I found this simple function, but its too simple, and mostly seems to generate "unknown error". But so far I haven't found anything that looks more promising.
I can do something like the following:
CComPtr<IErrorInfo> iei;
if (S_OK == GetErrorInfo(0, &iei) && iei)
{
// get the error description from the IErrorInfo
BSTR bstr = NULL;
if (SUCCEEDED(iei->GetDescription(&bstr)))
{
// append the description to our label
Append(bstr);
// done with BSTR, do manual cleanup
SysFreeString(bstr);
}
}
else if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
{
// append the description to our label
Append(CErrorMessage(HRESULT_CODE(hr)).c_str());
}
However, I wonder if I'm accomplishing anything more than _com_error.
Does anyone know of a reasonably fleshed out facility for generating error log output for HRESULTs?