Home
thelonelemming edited this page Sep 13, 2010
·
2 revisions
annex provides a simple and lightweight way to dynamically load shared libraries. To use annex:
1. Define a plugin interface using virtual functions
#include <annex/annex.hpp>
struct my_plugin_interface
{
virtual void do_something(std::string const& x) const = 0;
virtual void do_something_else() const = 0;
};
2. Define one or more implementations and expose them using a macro
#include "my_plugin_interface.hpp"
struct my_plugin : my_plugin_interface
{
void do_something(std::string const&x) const
{
// ...
}
void do_something_else() const
{
// ...
}
};
ANNEX_IMPLEMENT_PLUGIN(my_plugin)
3. Load and use the plugin using the annex::plugin<> template
#include "my_plugin_interface.hpp"
int main(int argc, char ** argv)
{
// load the plugin
annex::plugin<my_plugin_interface> plugin("my_plugin.dll");
// use the plugin
plugin->do_something("some string");
plugin->do_something_else();
return 0;
}