简体   繁体   English

如何以与平台无关的方式从c ++中调用.NET

[英]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.

相关问题 获得最大C ++浮点值的平台无关方法 - Platform-independent way to obtain maximum C++ float value C++:如何以独立于平台的方式读写多字节 integer 值? - C++: How to read and write multi-byte integer values in a platform-independent way? 在 C++ 中生成独立于平台的 GUID? - Platform-independent GUID generation in C++? C / C ++库,用于平台无关的二进制文件I / O - C/C++ library for platform-independent binary file I/O 用于C ++的独立于平台的并发编程库 - Platform-independent concurrent programming libraries for C++ 如何使我的课程与平台无关? - How can I make my classes more platform-independent? 如何以独立于平台的方式从 C++ 中的目录中读取文件? - How to read files from a directory in c++ in a platform independent way? 使用Java本机代码或C ++(QT,WxWidgets等)进行平台无关的编程 - Platform-independent programmming with Java native code or C++ (QT, WxWidgets etc.) 为什么C ++哈希函数的返回类型为std :: size_t,而不是与平台无关的类型? - Why C++ hash functions' return type is std::size_t, instead of a platform-independent type? 独立于平台的C ++调试器IDE,它们遵循诸如Visual Studio之类的指针 - Platform-independent C++ Debugger IDEs that follow pointers like Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM