As the description states. I have some static .lib files created in other rather large c++ projects containing a class I would like to be able to use in C#. What would the best way to use these classes from inside c#. The C++ libraries are not managed.
3 Answers
By far the easiest option is to build a wrapper library in C++/CLI.
8 Comments
I am afraid class exporting from native .lib files is not possible inside C#. But using C++ Cli, you could wrap the class and make use of it via wrapper .net class. But this approach also requires a header (.h or .hpp) file to included.
COM dlls are different story. They can be referenced in a C# project and MSVS automatically wrapps the native classes.
Comments
What @marcelo-cantos said: use C++/CLI as a bridge between the managed and unmanaged worlds. It is easy.
The only other options you have are:
(1) Write a wrapper DLL that exports extern "C" functions that call onto your existing C++ objects. Then use [DllImport] and PInvoke in C# to call the DLL's C functions.
(2) Wrap your native C++ classes in COM interfaces and use C# COM Interop to invoke methods on the classes.
The C++/CLI bridge is by far the easiest option.