P/Invoke a purely C++ library?

前端 未结 2 1778
無奈伤痛
無奈伤痛 2020-12-19 13:11

Is it possible to P/Invoke a pure C++ library, or does it have to be wrapped in C?

2条回答
  •  心在旅途
    2020-12-19 13:36

    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.

提交回复
热议问题