tags:

views:

63

answers:

1

Iam calling the functions using SMO of a c# dll in a c++ project but the code in that dll is throwing some exception, so how can I display the exception message in my C++ code

+1  A: 

It depends how you call it. If you use COM then you'll get a failure HRESULT. You can use IErrorInfo to retrieve the exception message. If you use something else then you'll lose the error context, all you can see is an SEH exception with exception code 0xe0434f4e, catchable only with the __try and __except keywords.

Using COM is heavily recommended.


EDIT after you posted code. Okay, you are using COM. And the smart pointers derived from _com_ptr_t that are created by the #import directive. These smart pointers turn failure HRESULTs into C++ exceptions. You'll need to catch a _com_error exception. That class also has the plumbing to get a suitable exception description, use the Description() method.

Hans Passant
Iam new to this SEH can you please give some example on how to use it
hr, hRes of HRESULT in the first block is showing success, any idea on this??
I updated my post.
Hans Passant
Hi,I pasted the output beneath the code. Call to getSQLInstances() is throwing some exception . I want to view what exception it is throwing.Can you please give some example how to do it?
You can find sample code in this thread: http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/3bef0e60-306b-4090-b321-9a1ca13272c8
Hans Passant
Thank you nobugz. It really helped me to find the exact exception description.