One easy way to call in C ++ is to create a wrapper assembly in C ++ / CLI. In C ++ / CLI, you can call unmanaged code as if you were writing your own code, but you can call C ++ / CLI code from C #, as if it were written in C #. The language was mainly developed with interop in existing libraries as a killer application.
For example - compile this with the / clr switch
#include "NativeType.h" public ref class ManagedType { NativeType* NativePtr; public: ManagedType() : NativePtr(new NativeType()) {} ~ManagedType() { delete NativePtr; } void ManagedMethod() { NativePtr->NativeMethod(); } };
Then in C # add a link to your ManagedType assembly and use it like this:
ManagedType mt = new ManagedType(); mt.ManagedMethod();
Let's open this blog post for a more explained example.
Eclipse Jun 01 '09 at 16:56 2009-06-01 16:56
source share