how to use c++ dll in c# project? [duplicate]

家住魔仙堡 提交于 2019-12-02 02:18:24

For using native C++ libraries in C#, you mostly will have to create a C++/CLI wrapper for that. P/Invoke is ok as long as the API of your DLL contains just simple C-like functions, but when the API contains real C++ classes, C++/CLI ist much better for that task.

You don't add a reference to a C++ library, that's for .NET assemblies only. What you need is platform interop using P/Invoke. MSDN has a bunch of information here:-

http://msdn.microsoft.com/en-us/library/aa288468(VS.71).aspx

It basically means you have to write method stubs that call your exported functions in the external library.

There is also the C++/CLI way which can be better depending on your C++ project setup, but personally I prefer the traditional Windows API function export way.

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