Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting (unmanaged) C++ to C# vs. using the C++ as a DLL in a C# application

Tags:

c++

c#

dll

I have a code library written in plain old C++ (no .NET/managed code) and I'm porting the application that uses this code to C#. I'm faced with two options:

  1. Rewrite the C++ code in C# to achieve the same functionality;
  2. Compile the C++ as a DLL and use it as a library in the C# application.

I'm relatively new to C# and am pretty unfamiliar with the implications of using an unmanaged code library in a C# app (or if there even are any). The code itself is moderate in size; it will likely take only a few days to rewrite in C#, but my thought is that leaving the code as a it is would allow me to use it in other applications as well (and to compile it on UNIX, etc).

What sort of things should I be aware of when making this decision? Are there any major drawbacks or gotchas to using the DLL in the C# application?

like image 208
Jeff L Avatar asked Jul 22 '09 17:07

Jeff L


1 Answers

I would make a wrapper library using C++/CLI to expose the library to C#. This can leave your library unchanged, and just wrap it for use from .NET, providing the best of both options.

like image 82
Reed Copsey Avatar answered Sep 28 '22 07:09

Reed Copsey