[英]Load Managed C++ Dll from Unmanaged C Dll?
I have an off the shelf product which supports custom plugins which need to be written in Unmanaged C. It doesn't support Managed Dll's and my language of preference is c#. 我有一个现成的产品,它支持需要用Unmanaged C编写的自定义插件。它不支持Managed Dll,我的首选语言是c#。
The information which needs to be passed back to the off the shelf product is very basic and can be held in a string. 需要传递回现货产品的信息非常基本,可以保存在一个字符串中。
So I was thinking I could do the following: 所以我想我可以做到以下几点:
Now communicating between a Managed C++ and C# Dll is easy. 现在,在托管C ++和C#Dll之间进行通信很容易。
But I cant figure out how to call a managed c++ function from an unmanaged c dll. 但我无法弄清楚如何从非托管c dll调用托管c ++函数。 Any help with some simple sample code would be great. 任何简单示例代码的帮助都会很棒。
Thanks 谢谢
EDIT: I created a Code Project article on how I did this with Alex's answer below. 编辑:我创建了一个代码项目文章,关于我是如何使用Alex的答案在下面做的。 http://www.codeproject.com/Tips/695387/Calling-Csharp-NET-methods-from-unmanaged-code http://www.codeproject.com/Tips/695387/Calling-Csharp-NET-methods-from-unmanaged-code
You almost got it right. 你几乎做对了。 Just put numbers 2 and 3 in the same C++/CLI DLL. 只需将数字2和3放在同一个C ++ / CLI DLL中。 You can both use .NET classes and export C functions from a C++/CLI project. 您既可以使用.NET类,也可以从C ++ / CLI项目中导出C函数。
extern "C" __declspec( dllexport ) void __stdcall PureExportC(
const wchar_t* param
)
{
CSharpAssemblyNamespace::CSharpWorker worker;
worker.DoWork( gcnew String(param) );
}
I don't think, you can do this. 我不认为,你可以做到这一点。 But you can write a c++ (unmanaged) plugin for the product. 但是你可以为产品编写一个c ++(非托管)插件。 Then write a stand allone managed app with c#, start it from the plugin and communicate between them using named pipes or sockets. 然后使用c#编写一个支持allone托管应用程序,从插件启动它并使用命名管道或套接字在它们之间进行通信。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.