你可以从C DLL调用C#DLL吗? [英] Can you call a C# DLL from a C DLL?

查看:151
本文介绍了你可以从C DLL调用C#DLL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C#中构建了一个DLL。现在,我想使用 R环境调用该DLL中的函数。 R环境支持调用非托管C / C ++ DLL,但不支持.NET DLL。所以我的问题是,可以从C / C ++ DLL调用C#DLL中的函数吗?如果是这样,你有没有链接到有关如何做的信息?

解决方案

最直接的方式是将C#DLL中的一个C#类公开为COM对象,然后从C / C ++ DLL中创建一个实例。如果这不是可接受的选项,您需要创建一个混合模式的C ++ DLL(其中包含托管和非托管代码)。您的C / C ++ DLL可以调用混合模式DLL中的导出函数,这可以将调用转移到C#类。


I've built a DLL in C#. Now I want to use the R Environment to call functions in that DLL. The R environment supports calling unmanaged C/C++ DLL's but not into .NET DLL's. So my question is, can I call functions in a C# DLL from a C/C++ DLL? If so, do you have a link to info about how to do this?

解决方案

The most straight forward way of doing this is to expose one of the C# classes in your C# DLL as a COM object, and then create an instance of it from your C/C++ DLL. If that isn't an acceptable option, you'd need to create a mixed-mode C++ DLL (which contains both managed and unmanaged code). Your C/C++ DLL can call exported functions in your mixed-mode DLL, which can in turn forward the calls on to your C# class.

这篇关于你可以从C DLL调用C#DLL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆