开发者

How to display exception message of managed C# code in c++ code

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 excepti开发者_开发技巧on message in my C++ code


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜