Link to home
Start Free TrialLog in
Avatar of darkriser
darkriser

asked on

HowTo throw custom C++ Exception and catch it in C# ?

I need to throw a custom exception in C++ DLL and catch it for further processing in C# code using this DLL. I need to pass a simple STRUCT having few unsigned int member variables. How to manage that?
Of course, I have access to both source codes, C++ and C#, as well...
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Just catching an exception from UNMANAGED code, you are going to lose information.

Here
    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/0624f3b3-5244-4cb8-be9c-29d464975d20/
they show (at the bottom) how to generate a wrapper that translates an exception (in their case, a string exception, but the unsigned would be similar).
Avatar of darkriser
darkriser

ASKER

thanks...
but this hint requires compilation using /clr option.
this is something I need to avoid.
unfortunately...
ASKER CERTIFIED SOLUTION
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is not the answer for my question but this is exactly how to solve my problem:-)
Thanks for those ideas...