Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to port a C++ library to C#?

I have a (header only) C++ library that I am looking to port to C#. It is a wrapper of the win api which I have made for a certain purpose. I want to port it to C# because I want to develop it further using C#. What is the most efficient (and easiest?) way to port it. Please note that I do not want something hectic because I don't want to spend more time porting the library than it took to make that library in the first place. So is there a way?

like image 260
ApprenticeHacker Avatar asked Aug 30 '11 16:08

ApprenticeHacker


1 Answers

It depends very much on how big your lib is, how it is structured, how your memory allocation looks like, how much you made use of libs not available in C# (like the C++ std lib), how much C++ template programming you have used etc.

Different strategies may be

  • try to port (parts of) it automatically by some code generator of your own
  • do not port it to C#, instead use C++/CLI (something I did very successfully in the past)
  • do it manually because the C++ concepts you have used so far don't map well to C#

"Header only" does not seem to make a real difference. In fact, things may technically get a little bit easier when you have just one C++ file for each class to be ported to one C# class file.

like image 151
Doc Brown Avatar answered Oct 12 '22 12:10

Doc Brown