Something like this using COMException
's HResult
property
unchecked
{
var msg = Marshal.GetExceptionForHR((int)0x80004005).Message;
}
Domanda
In my C# code I want to be able to log COMException
s so that not only hex representation of HRESULT
s (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?
Soluzione
Something like this using COMException
's HResult
property
unchecked
{
var msg = Marshal.GetExceptionForHR((int)0x80004005).Message;
}
Altri suggerimenti
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.