Build native c++ for use as .net library

≯℡__Kan透↙ 提交于 2019-12-04 19:29:17

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!