If I have a program foo.exe and it loads a plugin bar.dll at run time, how do I let the code in bar.dll use classes from foo.exe? And would it be possible for bar.dll to derive classes from foo.exe? Also, would the solution be cross-platform?
EDIT: Here's more of what I'm trying to do:
//foo.exe
class Node {
public:
void SetName(const string& n) { ... }
const string& GetName() { ... }
};
//bar.dll
class TransformNode : public Node {
public:
void DoSomething() {
SetName(...); //basically, can I inherit functionality from foo.exe (SetName and GetName)
//and reuse the code in a derived class in bar.dll?
}
};
In order to let bar.dll use classes from foo.exe, you need to pass an instance of a class with virtual functions from foo.exe to bar.dll. Bar.dll will call the virtual functions that came from foo.exe.
Yes, it is possible for bar.dll to pass derived clases back to foo.exe, and then have foo.exe call the virtual functions of said classes.
This solution would be cross-platform, but you are going to have major problems making sure you do not break abi between the shared library and the exe. Even the simplest of changes can easily break abi.
This is a good intro to what can break an abi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With