Pregunta

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?

¿Fue útil?

Solución

Something like this using COMException's HResult property

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top