It is possible to call back from plugin into application using pointer to function:
// plugin
void MyPlugin::someFunctionInPlugin(int (*functionInApp)())
{
int result = (*functionInApp)();
}
// application code
int someFunctionInApp()
{
...
}
void someOtherFunctionInApp()
{
plugin->someFunctionInPlugin(&someFunctionInApp);
}
// plugin
void MyPlugin::someFunctionInPlugin(int (*functionInApp)())
{
int result = (*functionInApp)();
}
// application code
int someFunctionInApp()
{
...
}
void someOtherFunctionInApp()
{
plugin->someFunctionInPlugin(&someFunctionInApp);
}
To copy to clipboard, switch view to plain text mode
Member function of class defined in application might be called from plugin if this function is virtual (at least it may compile without errors), or when it is passed via pointer to member function:
// plugin
void MyPlugin::someFunctionInPlugin(ClassInApp *obj, void (*ClassInApp::Fun)())
{
obj->virtualFunction();
((*obj).*(Fun))();
}
// application
class ClassInApp
{
virtual void virtualFunction();
void someMemberFunction();
};
void someFunctionInApp()
{
ClassInApp obj;
plugin->someFunctionInPlugin(&obj, &ClassInApp::someMemberFunction);
}
// plugin
void MyPlugin::someFunctionInPlugin(ClassInApp *obj, void (*ClassInApp::Fun)())
{
obj->virtualFunction();
((*obj).*(Fun))();
}
// application
class ClassInApp
{
virtual void virtualFunction();
void someMemberFunction();
};
void someFunctionInApp()
{
ClassInApp obj;
plugin->someFunctionInPlugin(&obj, &ClassInApp::someMemberFunction);
}
To copy to clipboard, switch view to plain text mode
Bookmarks