Pinvoking functions from a static C library

孤人 提交于 2021-02-07 20:53:00

问题


I have a native C++ library (static i.e. .lib target). I wish to use some of the functions in this file in my C# projects. For dlls, I could pinvoke them. How do I do this for static libraries?

I read this question and there David's answer says you can pinvoke only for dlls and not for libs.


回答1:


A static library is used by linking it into a larger module. In Windows that means a DLL or an executable.

They do not stand alone and only make sense when you link them into a larger module. So, that would imply that, in order to use pinvoke you need to build a DLL which includes the library, and pinvoke to that DLL.

As an alternative to pinvoke, you could make a mixed mode C++/CLI assembly. Link the static library to that C++/CLI assembly and expose the functionality via a C++ managed class. That managed class can then be consumed by your C# code.



来源:https://stackoverflow.com/questions/21005412/pinvoking-functions-from-a-static-c-library

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