插件模式与.dll。如何从dll提取插件接口? [英] plugin pattern with .dll. how can I extract plugin interface from dll?

查看:127
本文介绍了插件模式与.dll。如何从dll提取插件接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,假设要实现在插件模式。

插件位于dll文件,我正在载入它们,根据用户通过命令行给出的参数。也就是说,如果用户想要使用plugin1,他在运行应用程序时在命令行中将其命名为参数,我应该立即加载它。

由于我使用插件模式一个接口(因为在c ++中工作是一个抽象类),所有的插件类都实现。

我的困境是放在接口类的哪里?为了有dlls建立我将必须有一个接口的声明在每个dll。

我想避免需要改变接口在所有的dll中,当有需要改变接口。

另一方面,如果我在主应用程序中声明接口类,我的dll不会被编译和构建?

你有建议如何从dll中提取接口类,并放置它在主要的应用程序,所以当我想改变它的代码,不需要改变它在十几个地方(即,在每一个dll)。

I have an application that's suppose to be realized in plugin pattern.
Plugins are located in dll files and I'm loading them on the fly, depending on the parameter given from a user via command line. That is, if user wants to use plugin1 he types that name as a parameter in command line when running the app and I am supposed to load it on the fly.
Since I'm using plugin pattern I have an interface (since working in c++ it's an abstract class), that all of the plugins classes implement.
My dilemma is where to put the interface class? In order to have dlls built I will have to have a declaration of interface in every dll.
I want to avoid the need for changing the interface in all of dlls when there is a need for change in interface.
On the other hand if I declare interface class in main app my dlls wont be compiled and built?
Do you have a suggestion on how to extract the interface class from dlls and put it in the main app, so when I want to change it's code, wouldn't need to change it in a dozen of places (that is, in every dll).

提前感谢,

干杯

推荐答案

将接口定义存储在公共位置(在\inc子目录中的单独的.h文件),并且一旦更改了接口,就必须重新编译所有库。在C ++中没有办法。如果你需要唯一识别接口的能力,你可以使用像COM和更改接口ID每次你打破接口(再次你将不得不重新编译的实现,但与COM客户端将不会运行到未定义的行为,因为DLL地狱)。

You will have to store the interface definition in a common location (separate .h file in say \inc subdirectory) and you will have to recompile all the libraries once you change the interface. There's no way around that in C++. If you need the ability to uniquely indentify interfaces you can use something like COM and change interface id each time you break the interface (again you will have to recompile the implementations, but with COM the client will not run into undefined behavior because of DLL hell).

这篇关于插件模式与.dll。如何从dll提取插件接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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