P/Invoke or C++/CLI for wrapping a C library

前端 未结 6 780
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 08:45

Have a moderate size (40-odd function) C API that needs to be called from a C# project. The functions logically break up to form a few classes that will be API presented to the

6条回答
  •  眼角桃花
    2021-01-31 09:12

    For an API of this size (~40 total entry points), I would draw the dividing line between C++/CLI and P/Invoke based on how much "header file gunk" you have to duplicate in C#. If it's a small (to modest) amount, P/Invoke is fine. Once you start duplicating a lot of .H files in C#--especially for things that aren't exposed in your .NET API--you might be better off using C++/CLI.

提交回复
热议问题