How to use C ++ library from C # and .NET?

My question is closely related to how a DLL exports C ++ classes and common methods (C ++ language functions without C # concurrency).

I believe that you can call functions inside a extern "C"C # block by simply referencing a DLL and using DLLImport. But can you create a C ++ boilerplate type? What if a C ++ type does something crazy that is not supported in C #? Is there an RFC or related part of the C # specification ?

Thank...

EDIT: Now I came across P / Invoke , which should be valuable, but I'm still looking for a spec or standard regarding this.

+5
source share
3 answers

A good way to do this is to use managed C ++ to access unmanaged C ++ and compile it into an assembly.

+7
source

I believe that you can call functions inside the external "C" block from C # just by referencing the DLL.

Wrong, you should use DllImporteither the so-called PInvoke (Invoke Platform) to call your own C function from managed code. The link only works for .NET or COM compilers with automatically generated dlls .

Using C ++ from C # becomes a real nightmare due to a name change among other things.

++ Dll , . , ComVisible, , COM.

C- ++ API, .

EDIT:

, :

  • 1) C dll
    • : .lib Managed ++, dll .
    • PREFERRED: P/Invoke .NET(, )

  • 2) ++ dll
    • P/Invoke, (- , )
    • PREFERRED: .NET dll ++, , , , DLL.
    • DLL ( A), ++ (Compiler C), ( A) C ++ . P/Invoke Cll, 1)
+2

DLL , #. , ++ , . - DLL, DLL . , DLL , #.

, . -, ++ , , PInvoke. , CRT # . factory .

, , , . API- C DLL #. ++.

+1

All Articles