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

前端 未结 6 682
爱一瞬间的悲伤
爱一瞬间的悲伤 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:14

    Lots of good answers here - another perspective is the plan for the existing C API. Arguments for using PInvoke include:

    • You need to keep a C API around for compatibility with other C consumers
    • You need to keep the code in C as it's large and migration is too expensive

    Arguments for using C++/CLI include:

    • you want to move as much of the code as possible to the CLR

    In this case you can start with C++/CLI and then move more and more over to C#

提交回复
热议问题