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.
-
Do you mean the plug-ins should be written in c++ ? – xtofl May 25 '10 at 09:39
-
It depends on what operating system(s) you're targeting, to some extent – Paul R May 25 '10 at 09:46
-
yes. but i'm concerned about binary compatibility between main application and plug-ins written in c++ – sepisoad May 25 '10 at 09:46
-
Define well the stdc++ library version and processor you are targeting (x86, arm, x64, etc), and you should have your binary compatibility covered. What I just said is harder than it sounds and harder than it should be. – McBeth May 25 '10 at 10:45
-
@SepiDev Have you considered simply writing the entire application in Python? These days, there aren't many things C++ can do that Python can't. – Rakis May 25 '10 at 13:07
3 Answers
You should :
- define an interface
- load your plugin and give it this interface
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.

- 2,302
- 1
- 19
- 38
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, using boost::python
).

- 4,945
- 2
- 26
- 27
-
-
although python is a viable solution and is widely used as an extending language, I need to decline the dependencies of the final application, – sepisoad May 25 '10 at 09:53
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)

- 1,066
- 12
- 26