Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/CLI or C# P/Invoke for a big C library, calling an extern function

Now I know there are quite a few questions regarding this but in general they refer to c++ libraries.

I have a fairly important C dll (approximately 2800 functions) and I need to make an API for about 70 of these callable in C#. I started off using P/Invoke but it's pretty tedious because I have complex structures to pass and return from the C code (structures with pointers to others, double pointers, etc) and it's taking me alot of time to get what I need.

Now I don't know C++/CLI at all but I have a bit of experience with C++ (not a lot though).

I am wondering if it's worth making the effort to learn this for my project. Will using a C++ wrapper enable me not to have to struggle with marshalling structures, allocating pointers in global heap, etc or not?....

Thanks a lot and big ups to this great community

like image 574
nche Avatar asked Jan 19 '23 17:01

nche


1 Answers

That's quite a large surface area. I think C++/CLI will be easier than P/invoke. You don't need to use any C++ features, you can write what is essentially C and compile and export it with C++/CLI.

like image 77
David Heffernan Avatar answered Jan 30 '23 20:01

David Heffernan