Вопрос

In my C# code I want to be able to log COMExceptions so that not only hex representation of HRESULTs (for example, 0x80004005) is output but also the corresponding WinError.h define symbol (such as E_FAIL) is output.

If I call ToString() on the exception reference there's a hex representation only.

Is there a built-in way to get the E_FAIL-like human-readable constants for the HRESULT values inside COMException objects?

Это было полезно?

Решение

Something like this using COMException's HResult property

unchecked
{
    var msg = Marshal.GetExceptionForHR((int)0x80004005).Message;
}

Другие советы

Look here - http://msdn.microsoft.com/en-us/library/windows/desktop/ms679351%28v=vs.85%29.aspx at FORMAT_MESSAGE_FROM_SYSTEM. It returns human-readable message about passed error code.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top