tags:

views:

111

answers:

4

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
A: 

You need to use P/Invoke & its marshalling

Necrolis
I would use this for C dlls but for C++ for sure not...
jdehaan
+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
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