Auto wrap c++ dll into c#

不打扰是莪最后的温柔 提交于 2019-12-03 17:33:57

SWIG can help create a wrapper consisting of two parts, one C++ sided, and one C# sided.
It needs a bit of work to set up the correct generation files though.

An alternative that requires more manual coding is C++/CLI.

For pure c apis I prefer p/invoke over either of them. There is a program to automate conversion of c headers. If I recall correctly it's called something like "P/Invoke Interop Assistant" or "Interop Signature Toolkit".

There is also mono/cxxi which looks pretty cool.

The procedure of using native .dll's in .Net is called P/Invoke. Look at http://pinvoke.net/ for some examples.

Note that you must match the build target with the version of the .dll. So for x86 .dll's you need to lock your project to x86, same with x64.

Note2 that you only need to lock the executing project (.EXE), not any additional projects loaded from the .EXE. .Net will automatically match .Net .dll's to CPU target type if they are set to ANY.

From http://social.msdn.microsoft.com/forums/en-US/clr/thread/c957959e-0f0c-422e-a5be-4ccfdd12e63d: You can use "dumpbin /exports " or dependency walker (depends.exe) to look at the exported symbols. They are both included in Visual Studio.

If this is unmanaged code then you could use P/Invoke. Another possibility is to use the C++/CLI extensions to compile the code into a managed assembly that you could directly use.

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