Calling C# from native C++, without /clr or COM?

后端 未结 2 620
無奈伤痛
無奈伤痛 2020-12-16 03:33

This question has been asked before, but I never found a truly satisfying solution -

I have a class library written in C#, and I want to call it from a legacy native

相关标签:
2条回答
  • 2020-12-16 04:03

    If you want to do this cross platform, I would recommend going with a 100% Mono approach.

    Mono has a clean Embedding API which works on Linux and Windows.

    0 讨论(0)
  • 2020-12-16 04:10

    With .NET 5.0 (the successor of .NET core) this is now possible to call C# from C++ in a cross-platform way without using Mono. Please see the solution explained in this Github issue using DNNE to generate a shared library and GCHandles to access C# objects.

    With this you get a shared library that can be used from C or C++. Note that this will give a C-like API (no objects, like when using extern C in C++), in the future there may be tools like SWIG for C++ to overcome this limitation.

    0 讨论(0)
提交回复
热议问题