user236520
user236520

Reputation:

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.

Upvotes: 7

Views: 505

Answers (1)

JaredPar
JaredPar

Reputation: 754615

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.

Upvotes: 1

Related Questions