问题
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