views:

727

answers:

3

I have a legacy DLL which contains a couple of methods I need to call from C# code. One of these methods takes in a pointer to another C++ class that lives within other C++ programs, not the DLL.

I'm pretty sure I need to use pinvoke to marshal the objects back and forth, but I haven't found anything on marshaling custom objects.

What would be the best way of accomplishing this?

+1  A: 

Are you sure it's a class and not a struct? After all, different compilers could choose to lay the class out differently in memory which would break the target DLL.

Have you considered using a Managed C++ wrapper?

Rowland Shaw
+1  A: 

I'd look at C++/CLI although COM interop may be easier depending on the shape of your C++ code.

Matt Davison
A: 

if its just a few methods use swig

iterationx