How can I (is there a way to) convert an HRESULT into a system specific error message?
- by Billy ONeal
According to this, there's no way to convert a HRESULT error code into a Win32 error code. Therefore (at least to my understanding), my use of FormatMessage in order to generate error messages (i.e.
std::wstring Exception::GetWideMessage() const
{
using std::tr1::shared_ptr;
shared_ptr<void> buff;
LPWSTR buffPtr;
DWORD bufferLength = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetErrorCode(),
0,
reinterpret_cast<LPWSTR>(&buffPtr),
0,
NULL);
buff.reset(buffPtr, LocalFreeHelper());
return std::wstring(buffPtr, bufferLength);
}
) does not work for HRESULTs.
How do I generate these kinds of system-specific error strings for HRESULTs?