How can I call unmanaged C++ Class DLL from C#?
+4
A:
You may want to create a managed C++ wrapper for that class, compile it with /clr (common language runtime support) and then you can use it in C#. You may also want to look at PInvoke.
testalino
2010-09-23 07:20:19
I would use this for C dlls but for C++ for sure not...
jdehaan
2010-09-23 07:27:52
+1
A:
The CLR doesn't support directly using native C++ classes, it prefers static methods to call via PInvoke or COM interfaces to use via COM interop. So some kind of C++ wrapper is required.
Mattias S
2010-09-23 07:24:25
A:
For example like this :
public unsafe class CppFunctionImport
{
[DllImport("ImageProcessingCpp.dll", EntryPoint = "PerformMovingAverage", ExactSpelling = true, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]//!-!
public static extern void PerformMovingAverage
(
ref byte *image,
int width,
int height,
int stride,
int kernelSize
);
}
Create your small wrapper, import desired functions and call