How can I (is there a way to) convert an HRESULT into a system specific error message?

Posted by Billy ONeal on Stack Overflow See other posts from Stack Overflow or by Billy ONeal
Published on 2011-01-04T20:10:24Z Indexed on 2011/01/04 20:54 UTC
Read the original article Hit count: 166

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about Windows