Question

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?

Was it helpful?

Solution

Something like this using COMException's HResult property

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top