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

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

问题描述

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

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?

推荐答案

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

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天全站免登陆