Tyler Durden
Tyler Durden

Reputation: 1228

Pinvoking functions from a static C library

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.

Upvotes: 4

Views: 3183

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

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.

Upvotes: 3

Related Questions