0

The answer found here is not the one I want: when fed with 0x80131500, the _com_error class says "Unknown error 0x80131500"

If you read that other answer, you'll find that what I really need is being able to call that Marshal.GetExceptionForHR(hr).Message piece of code from C/C++

Question: HOW to achieve same result as Marshal.GetExceptionForHR(hr).Message from C/C++?

I will accept any answer which ultimately allows me to have something other that "Unknown error" for 0x80131500, which is not "unknown", it's COR_E_EXCEPTION.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
manuell
  • 7,528
  • 5
  • 31
  • 58
  • 1
    Check my answer in the same link https://stackoverflow.com/a/7008279/403671. There's no magic bullet. `Marshal.GetExceptionForHR(unchecked((int)0x80131500));` will get you "Exception of type 'System.Exception' was thrown." If you know the module (.dll) that contains error definition, you can get to it, but it cannot be automatic – Simon Mourier Nov 23 '22 at 12:48
  • I fully understand the "no silver bullet" part... *but* I find "An exception of type 'System.Exception' was thrown" vastly superior to ""Unknown error" – manuell Nov 23 '22 at 14:38
  • 1
    Decoding this particular [`HRESULT`](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a) value, you'll find that its facility code is 0x13, i.e. `FACILITY_URT`. All of those error codes are listed in *CorError.h* (under the NETFXSDK directory). While the header has the following comment: *"Add new HRESULTS **along with their corresponding error messages** to corerror.xml"*, I'm not aware of a public API to get to those error messages. – IInspectable Nov 23 '22 at 14:39
  • See the comments in https://github.com/dnobori/DN-OSS-Learn/blob/master/corecrl-181216/coreclr-master/src/inc/corerror.xml and https://github.com/tpn/winsdk-10/blob/master/Include/10.0.10240.0/um/CorError.h – Remy Lebeau Nov 23 '22 at 18:36
  • 1
    The CLR implements [IErrorInfo](https://learn.microsoft.com/en-us/windows/win32/api/oaidl/nn-oaidl-ierrorinfo), its GetDescription() function gives you the exception's Message property. – Hans Passant Nov 23 '22 at 20:42
  • As far as I'm concerned, If you want to obtain an error string for `system error codes`,you could use the [FormatMessage function](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessage). Refer to the Doc:[Retrieving Error Messages](https://learn.microsoft.com/en-us/windows/win32/seccrypto/retrieving-error-messages) The HRESULT From WIN32 Error Code Macro converts a Win32 error code to an HRESULT using the pattern `0x8007XXXX`. `0x80131500`is not a win32 error. – Jeaninez - MSFT Nov 24 '22 at 02:29
  • @HansPassant This is CRAZY! Your comment made me search this site for how to get an `IErrorInfo` after a COM error, and I directly found this answer https://stackoverflow.com/a/21240424/1374704, whose author is.. . ME. It was 9 years ago and I have already forgotten... – manuell Nov 24 '22 at 07:25

0 Answers0