/// <summary> /// Try to get the error message for GetLastError result /// </summary> public static string LastErrorToString(int error) { return(String.Format( CultureInfo.CurrentUICulture, "Error {0}: {1}", error, NativeErrorHelper.FormatMessage(error))); }
/// <summary> /// Try to get the string for an HRESULT /// </summary> public static string HResultToString(int result) { string message; if (HRESULT_FACILITY(result) == FACILITY_WIN32) { // Win32 Error, extract the code message = NativeErrorHelper.FormatMessage(HRESULT_CODE(result)); } else { // Hope that we get a rational IErrorInfo Exception exception = Marshal.GetExceptionForHR(result); message = exception.Message; } return(String.Format( CultureInfo.CurrentUICulture, "HRESULT {0:D} [0x{0:X}]: {1}", result, message)); }