简体   繁体   English

从DLL导出接口。 C#Delphi VB C ++等

[英]Export Interface from Dll. C# Delphi VB C++ etc

I've created an application in Delphi that is capable of loading plugins from a dll. 我已经在Delphi中创建了一个能够从dll加载插件的应用程序。 The dll exports one function which looks like this dll导出一个看起来像这样的函数

function GetPlugin: IPluginInterface;

IPluginInterface is a ActiveX Type Library. IPluginInterface是一个ActiveX类型库。 I figured because I was using a type library I could then use C# or any other language to export IPluginInterface from a dll, though after a bit of googling I found out this is not the case as there is a lot of talk of managed and unmanaged code and reasons why this can't be done. 我认为是因为我使用的是类型库,然后可以使用C#或任何其他语言从dll导出IPluginInterface,但是经过一番谷歌搜索后,我发现情况并非如此,因为有很多关于托管和非托管的讨论代码以及无法执行此操作的原因。 So my question is, am I still able to create a plugin in C# that will export a function like above? 所以我的问题是,我仍然能够在C#中创建一个插件,该插件将导出上述功能吗? If not, what languages are able to do that apart from C++? 如果没有,除了C ++之外,还有哪些语言能够做到这一点?

So my question is, am I still able to create a plugin in C# that will export a function like above? 所以我的问题是,我仍然能够在C#中创建一个插件,该插件将导出上述功能吗? If not, what languages are able to do that apart from C++? 如果没有,除了C ++之外,还有哪些语言能够做到这一点?

All of the mainstream programming environments on Windows can produce and consume COM interfaces. Windows上的所有主流编程环境都可以产生和使用COM接口。 C, C++, C#, VB6, VB.net, Delphi and so on. C,C ++,C#,VB6,VB.net,Delphi等。 So, yes, you can use COM interfaces for your task. 因此,是的,您可以使用COM接口执行任务。

As a point of detail, what you can't do is pass an interface out of a Delphi DLL as the return value of a function. 详细地说,您不能做的是将接口从Delphi DLL中传递出去,作为函数的返回值。 That's because Delphi uses non-standard semantics for function return values . 那是因为Delphi对函数返回值使用了非标准的语义 Instead you need to return it via an out parameter. 相反,您需要通过out参数返回它。

So you'd need to write your GetPlugin like this: 因此,您需要像这样编写GetPlugin

procedure GetPlugin(out Plugin: IPluginInterface); stdcall;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM