Ecere SDK/eC Forums
http://www.ecere.com/forums/
Print view

Dynamic loading/plugins
http://www.ecere.com/forums/viewtopic.php?f=1&t=361
Page 1 of 1
Author:  Heiko [ Fri May 31, 2013 11:57 pm ]
Post subject:  Dynamic loading/plugins

Hi,

i am new to eC and i am trying make a application where i deliver a binary which is the application and allow the users to extend the application by making 'plugins' that are loaded dynamically on application start.

would this be possible with eC?
Author:  jerome [ Sat Jun 01, 2013 12:31 pm ]
Post subject:  Re: Dynamic loading/plugins

Hi Heiko!

Welcome to eC! This is totally possible, and made easy.

The plugins projects must be set up as dynamic library (.dll/.so/.dylib).
Say you would like to load all plugins from a folder, you can use the FileListing class to iterate through the files in a folder, and load them with eModule_Load(), e.g. if the plugin is called myplugin.dll/libmyplugin.so/libmyplugin.dylib :

Code: Select all

Module module = eModule_Load(__thisModule, "myplugin", publicAccess);
This will give you a module handle, from which you can find a class and instantiate it:

Code: Select all

Class c = eSystem_FindClass(module, "MyPluginClass");
eInstance_New(c);
A common approach would be to define a base class with virtual methods in the application, which your plugin class can derive from and override the methods it wants to implement.

Please let me know if you have more questions regarding this after you try it out. Good luck!

Best regards,

Jerome
All times are UTC-05:00 Page 1 of 1