Calling unmanaged C++ Class DLL from C#
How can I call unmanaged C++ Class DLL from C#?
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.
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.
You need to use P/Invoke & its marshalling
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
精彩评论