views:

69

answers:

1

I have an unmanaged DLL written by another developer in unmanaged C++. My application is a WinForms application written in C#. I am using interop to call a method (function) in the native DLL. The call is causing my application to crash upon executing the method.

How does one safely call a method using interop, so that it does not bring the app down?

+3  A: 

You could create a seperate AppDomain and load the unmanaged DLL in it. If the call crashes, it will just crash the AppDomain and your application will still live

Nitin Chaudhari
This will not always help you. Unmanagad code can still take out the whole process if, for example, it trashes the stack and certain other kinds of corruption can take out the process without letting the managed code bail out first. AppDomains are a purely managed construct and don't do anything to protect unmanaged code.
Dean Harding