views:

618

answers:

1

I have a DLL that is created in C# for the purpose of providing a COM interface to a third-party C# library. I have a C++ program that uses that COM interface so that it can communicate with the C# library. Sometimes, exceptions get thrown on the C# side and all I get back on the C++ side is an HRESULT from the COM invocation that says means "exception occurred" (or something to that effect). Is there any way for me to get the entire exception information so that I can print an informative message to my C++ app's log? If not, is there anything I can do on the C# side to intercept all exceptions before they trigger whatever mechanism returns the HRESULT to C++ so that I can log them on the C# side?

+4  A: 

There is a mapping of a managed exception to an HRESULT. Consult the table in this MSDN article. .NET retrieves error info from a COM object with IErrorInfo. That might well work the other way around too. Worth a shot.

Hans Passant
My reading at that link you provided gives me hope. Do you know of any ATL class that does all the necessary querying of interfaces for me, or am I going to have to do it myself?
rmeador
ATL implements IErrorInfo, you want to go the other way around. It's a very simple interface. ISupportErrorInfo::InterfaceSupportsErrorInfo() first, then IErrorInfo::GetDescription(). QI to get the interface pointers.
Hans Passant