基于c/c++的插件架构应用
我需要知道如何开始编写基于插件架构的应用程序。我的意思是如何编写基本代码并让其他人通过添加他们编写的插件来开发应用程序。 我知道在c++中这样做存在一些问题。大多数人使用另一种语言(例如 python)将插件添加到他们的 C++ 应用程序中。
I need to know how to start writing an application based on plug-in architecture. I mean how to write a base code and let others develop the application by adding the plug-ins they write.
I know that there is some problems in doing so in c++. most people use another language such as python to add plug-ins to their c++ application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该:
您的插件将能够通过此接口与主机应用程序进行通信。这意味着,您必须仔细考虑您希望插件执行的操作。
如果您的主机应用程序发生变化并且添加了功能,您可能需要支持各种版本的接口。
You should :
Your plugin will be able communicate with the host application through this interface. That means, you must think carefully at what you want your plugins to do.
You will probably need to support various versions of the interface if your host application changes and you add functionnalities.
我认为,这不是您期望的答案,但您可以尝试检查 Rainmeter 来源。它是用 C++ 编写的(在我看来,有些地方可以做得更好,但总的来说还可以),整个应用程序都是这样完成的,所以它只处理插件。
即使简单的 API 也是通过插件完成的,我的意思是,还有一堆贡献插件的示例,是由其他人编写的(有一天我也这样做了)。
我认为您实际上可以通过查看其他应用程序来研究基于插件的开发中的许多新技巧。
另外值得一提的是,另一个很好的示例是 Miranda IM。
编辑: 另外,如果我执行相同的任务,我实际上会向我的应用程序添加一些
python
(或类似的东西)后端,并将其用作 SDK 的语言(例如,使用boost::python
)。I think, this is not the answer you expect, but you could try to examine the Rainmeter sources. It's written in C++ (some places could be done better, to my mind, but overall it's ok) and the whole application is done the way so it just handles plugins.
Even the simple API is done via plugins, there is also a bunch of examples of contributed plugins, I mean, written by someone else (I did that too, one day).
I think you could actually study a lot of new tricks in the plugin-based development by looking at other applications.
Also to mention, another good sample is Miranda IM.
Edit: Also, if I han the same task, I would actually add some
python
(or something like that) backend to my application and use it as the language for SDK (for example, usingboost::python
).您可以在应用程序中定义外部应用程序可以与之通信的访问点吗?
假设您定义了一些命名管道机制或 TCP/IP 套接字,外部应用程序将在其中调用此 API 来操作您的应用程序?
鉴于您需要在核心应用程序中注册这些插件,然后才能允许它们使用您的应用程序。您甚至可以添加公共私有证书来验证此插件的来源(即使用私钥对插件进行签名,其中应用程序的实例将根据公钥进行验证)
could you define access points in your application where an external application could communicate with?
let's say you define some named pipe mechanism or a TCP/IP socket, where the external application would call this API to manipulate your application?
given that you need to register these plugins in the core application before allowing them to use your application. you might even add public private certificates to authenticate the origin of this plugin, (i.e. to sign the plugin with a private key where instances of your application would validate against a public key)