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.
到目前为止,最简单的选择是在C ++ / CLI中构建包装器库。
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.