Write a plugin in openFrameworks. Write an app which can load those plugins at runtime in openFrameworks. You have:
- Application has
- Plugin has
- Application contains an abstract class definition
- Plugin has a class
- Application loads Plugin, and now can create instances of
Module- A (non-abstract) class which the Plugin provides (this is the content of your plugin, your plugin may define 1 or more
ModuleBaseType- A (abstract) class which the Module inherits from
Factory<Module>- A class which can instantiate other classes, e.g. a
Factory<MyModule>can create instances of
FactoryRegister<ModuleBaseType>- A class which contains a list of
Factorys. All the
Factorys inside this register will create
Modules which inherit from
Requirements / Compatability
Currently runs on oF 0.9.0 in Windows. Thanks to work by @satoruhiga, ofxPlugin will compile in OSX without issues, but the main plugin loading features are still untested.
Tested on Visual Studio 2015, but should work on earlier versions too (be aware of changing the
Platform Toolset option in all the relevant projects).
You must have the following addons available in your
- ofxSingleton (tested with 3af7ff04ff2fcb71a11c0960e8dfe32f043f4165 on 2015/10/08)
- ofxAddonLib (tested with 6c3b3a6bfcaacf8b6340abb8444030e604b65e89 on 2015/10/08)
Factory is something which instantiates classes for you. For each module (i.e. class type), you'll have one
Factory which can instantiate that class at runtime.
ofxPlugin provides a
FactoryRegister where you can store all these factories. When you load a plugin, it adds the factories from that plugin to the
ModuleBaseType must be a non abstract class, i.e. it cannot have something like
virtual void draw() = 0;. This hurts I know, but it's necessary for a factory model to work in many situations.
Your plugin needs references to openframeworksLib, ofxSingletonLib, and anything else it references.
Current limitations / Known issues
- All plugins in one dll must inherit from the same
- Plugins are never unloaded until the application terminates (you can still manually remove factories from the