Here’s a scenario I’m exploring for a plugin framework:
A third party plugin developer designs a DLL with a known entry point and arbitrary parameters. They also provide details of the entry point and parameters in an XML file and provide data which they’ll be called back with by my program when the plugin is invoked. They’ll be alble to use a set of extensible variables in the XML which my program will expand and pass back to them through the parameters they specify.
I know that in win32 I can use LoadLibrary/GetProcAddress to get hold of the function they define. What I’m less clear about is whether I can dynamically generate a function specification from their defined parameters which I can use to call them back with. Anyone know if this is possible?
What I decided to do is to simply make the plugins accept a simple interface of:
This would allow the user to specify their parameters in the XML and then define a structure which they expect me to pass them, e.g.
When they get this message from me, they can check the size before using the buffer to ensure that the XML and the structure match.
As I parse the XML, I use this class with template methods to dynamically construct the object:
This allows me to perform the following kind of operation as I parse the XML:
It’s not perfect, and it’s a bit old school, but at least it’s simple and provides a reasonable level of safety.