Probably the best way here is to use P / Invoke or Platform Invoke. Depending on the structure or interface of the C ++ dll, you can wrap it in a clean C interface; this is easiest if your interface uses only blittable . If you restrict your dll blittable interface to types (Int32, Single, Boolean, Int32 [], Single [], Double [] - the basics), you do not need to perform complex data marshalling between managed (C #) and unmanaged (C).
For example, in C # code, you define the available calls in your C / C ++ dll using the DllImport attribute.
[DllImport, "ExactDllName.dll"] static extern boolean OneOfMyCoolCRoutines([In] Double[] x, [In] Double[] y, [Out] Double result)
Small [In] and [Out] are not strictly required, but they can speed things up. Now by adding your "ExactDllName.dll" as a link to your C # project, you can call your C / C ++ function from your C # code.
fixed(Double *x = &x[0], *y = &y[0] ) { Boolean returnValue = OneOfMyCoolCRoutines(x, y, r); }
Note that I essentially pass pointers back and the fourth between my dll and C # code. This can lead to memory errors, since the location of these arrays can be changed by the CLR garbage collector, but the C / C ++ dll will not know anything about it. Therefore, to protect myself from this, I just fixed these pointers in my C #, and now they will not move in memory, while my dll works on these arrays. This is now unsafe code, and I will need to compile C # code with this flag.
There are many small details for language interaction, but this should make you go for a ride. Sticking to a stateless C-interface of blittable types is a great policy, if possible. This will allow your language to intercept the cleanest code.
Good luck
Floor