1

Creating custom HRESULT has been covered here Creating your own HRESULT?

Solution to above question is fine for c++ native clients, they can use the returned HRESULT to FormatMessage() and get error string, what about C# and JavaScript client? For discussion's sake let us forget FormatMessage() via PInvoke.

e.g. if a COM function returns E_ACCESSDENIED and C# client will receive it via nicely packaged exception, complete with error string and symbolic name(E_ACCESSDENIED)

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

It is understood system error codes have been mapped to .Net exceptions. Questions is how to return an message compiler generated custom error codes packaged in HRESULT?

Is MAKE_HRESULT the answer?

Community
  • 1
  • 1
Logan
  • 184
  • 10
  • 2
    Check out and implement the [`IErrorInfo` interface](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221233%28v=vs.85%29.aspx). Also, your custom HRESULT values should be in the proper custom HRESULT facility. – Cheers and hth. - Alf Jun 08 '15 at 11:08
  • that works like a charm for JavaScript, but C# still doesn't produce pretty messages. – Logan Jun 08 '15 at 11:13
  • Sorry, I have no direct experience with this stuff since 15 years ago. Otherwise your description might have triggered some "aha, that's what it's about" recognition circuit. :( – Cheers and hth. - Alf Jun 08 '15 at 11:17
  • https://msdn.microsoft.com/en-us/library/awy7adbx.aspx says that it _ought_ to work... – Roger Lipscombe Jun 08 '15 at 11:18
  • 2
    Works fine in C# as well, the CLR always queries for ISupportErrorInfo. You can see it being done [here](https://github.com/dotnet/coreclr/blob/master/src/vm/stdinterfaces.cpp). You must be doing it wrong, we can't see you doing it wrong. – Hans Passant Jun 08 '15 at 11:46
  • yes, `COM_INTERFACE_ENTRY(ISupportErrorInfo)` was missing so QI must be failing for CLR. – Logan Jun 09 '15 at 05:29

0 Answers0