Creating a C ++ Dll and calling it from C #

In my project, I got a device that comes with C ++ code examples. The codes are OK and the device is working properly.

But I need him to talk to my C # interface, because currently all other devices use the C # interface.

So, I plan to create a Wrapper DLL for the driver. I will create my own C ++ library (from the source code with the appropriate interface) and call this C ++ library from C # using DLLImport (just call my interfaces there.).

I am sure that this can be done like this, but I have never created a C ++ library and have not used it with C #. So, can anyone refer to some textbook on my problem?

I am using C ++ / C # int VS.NET 2008.

Regards, Maksoud

+3
source share
4 answers

Another useful tool you have is the C ++ CLI .

You can use the C ++ CLI to create an intermediate library - one that provides managed classes but runs unmanaged C ++ code. In fact, you can mix managed and unmanaged C ++ in the same DLL.

The unmanaged part can access unmanaged DLLs without using the PInvoke functions.

Your C # code can access managed classes in this staging library.

+2
source

DLL , , . , P/Invoke . , /.

+1
source

For those who come to this question and are looking for answers, you can try xInterop NGen ++, the C # cover generator for your own C ++ DLL , which was just released to the public, the tool can automatically create a C # computer for your own C + + DLLs using advanced P / Invoke technologies. Check the current version and a free version will be released soon.

(I am the author of the tool)

0
source

Source: https://habr.com/ru/post/1726419/


All Articles