Question

I have the c++ source code of functionality which is appealing to me.

What effort/work is involved/required in order to either reference this from a .net application or build this code as a .net assembly (preferably c#)?

This is my first attempt at porting code, so please breakdown your answer for me step by step.

Was it helpful?

Solution

There are several ways of doing it.

  1. PInvoke
  2. Create C++/CLI wrapper around your C++ native code (make static library out of C++ native code) and C++/CLI generated assembly can be easily utilized in .net application.
  3. COM, i.e using interop (which is difficult among all the options)

In my suggestion easiest way is to use option 2, but you need to take care of proper marshaling.

OTHER TIPS

Solution A:

  1. If you have the source code, then compile the CPP program as a DLL file.
  2. Use P/Invoke

Solution B (if the functionality you want is in a static library):

  1. Create a stub function caller and compile THAT as a DLL
  2. Same as solution A.2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top