P/Invoke a purely C++ library?
Is it possible to P/Invoke a pure 开发者_如何学JAVAC++ library, or does it have to be wrapped in C?
C++ libraries can be P/invoked, but you'll need to use "depends" to find the mangled method names (names like "@0!classname@classname@zz") and for instance methods use "ThisCall" calling convention in the p/invoke and pass the reference of the instance as the first argument (you can store the result of the constructor within an IntPtr).
A "pure" C++ library will have its name mangled by the compiler, so it will be hard to get the P/Invoke declaration correct. And a C method gets an underscore at the beginning, which may not be there in C++. And a C++ method needs a this instance as a first parameter, you'd have to give it yourself.
I think that you need to wrap your C++ API in a C-compatible series of methods.
精彩评论