简体   繁体   中英

How do I call .NET from c++ in as a platform-independent way as possible

I have a C++ app from which I want to call .NET (C#) methods. I was going to use C++/CLI , but it is only supported on Windows.

Since also we support the MAC, I'd like to call .NET from C++ in a way that will work on both Windows and Mac (with Mono).

What is the best way to do this?

EDIT: I should add that the c# code we wish to call is not ours. We have no way of making any changes to it. The c++ code, of course, is ours.

The easiest way is to expose the functionality via a function pointer. Both .Net and native code can interop with C/C++ code in the form of a function pointer. Function pointers are supported on all platforms where C++ code runs hence it can be written without any understanding of .Net.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM