Plug Ins and such

I'm trying to set up a type of plug-in system for a program I'm writing. My idea is to have the plug-ins be an class of a certain type, and have an XML file that contains information about each plug-in. My idea was to have a place in the XML file that has the class name of the plug-in to be loaded, but that's where I get stuck. I was wondering if there was a way to call a constructor based on a string of the class name?

Also, another place where I get stuck is how to actually make the plug-ins. I have a certain directory in my program for plug-ins, and when I call something like "MyPlugin plugIn();" it would look for a file in that directory that had the code for it. I was thinking .dll files were what I needed, but I'm not sure if I'm right, nor do I have any experience with them.

My idea is to be able to do something like so:

1
2
3
4
5
6
string pluginName = "MyPlugin"; // This would be dynamically set from a list of installed plug-ins

/* This function would create an object (who's code would be located in a directory called Plugins) and that sort of thing */
Plugin plugin = loadPlugin(pluginName);

// Do stuff with plug-in 


I hope that makes sense. Can anyone point me in the right direction of what types of things I need to look at for this?
That is exactly what DLLs are for.

You can also attach a manifest to the DLL, so that your program can open the DLL file and just read the XML plugin information from the end of the file.

To learn how to do DLLs with C++, start here:
http://www.google.com/search?q=howto+c%2Fc%2B%2B+dll

The trick with a plug-in architecture is to have your exe also have a plug-in architecture, where important classes/data structures are passable between the DLL and your program. You'll have to design an API (a specific list of functions) that allows the plugin to do things.

The function names will, of course, have to be fairly generic, because each plugin will do something different with them. There will also be some very specific functions to handle memory allocation, passing class data, etc.

Try googling around the type of program you are writing and learn as much as you can about what it is to do before you start writing very much of your program -- a strict design is most important here.

Hope this helps.
Sorry I'm late in responding, but thank you very much for your help. The information you have provided put me on a good path of learning about DLLs and such.
Topic archived. No new replies allowed.