您还可以从一个C DLL中的C#DLL? [英] Can you call a C# DLL from a C DLL?

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

问题描述

我已经建立在C#中的DLL。现在我想使用ř环境的调用函数中该DLL。第r环境支持调用非托管的C / C ++ DLL的,但不进.NET的DLL。所以我的问题是,我可以调用一个C#DLL函数从C / 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作为一个COM对象的C#类中的一个,然后创建它的一个实例你的C / C ++ DLL。如果这不是一个可以接受的选择,你需要创建一个混合模式C ++ DLL(其中包含托管和非托管code)。你的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天全站免登陆