[英]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. 我有一个C ++应用程序,我想从中调用.NET(C#)方法。 I was going to use C++/CLI
, but it is only supported on Windows. 我打算使用C++/CLI
,但它仅在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). 既然我们也支持MAC,我想以一种可以在Windows和Mac上运行的方式从C ++调用.NET(使用Mono)。
What is the best way to do this? 做这个的最好方式是什么?
EDIT: I should add that the c# code we wish to call is not ours. 编辑:我应该补充一点,我们希望调用的c#代码不是我们的。 We have no way of making any changes to it. 我们无法对其进行任何更改。 The c++ code, of course, is ours. 当然,c ++代码是我们的。
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. .Net和本机代码都可以以函数指针的形式与C / C ++代码互操作。 Function pointers are supported on all platforms where C++ code runs hence it can be written without any understanding of .Net. 在运行C ++代码的所有平台上都支持函数指针,因此可以在不了解.Net的情况下编写函数指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.