Sign in to follow this  

Plugin Architecture

Recommended Posts

Hey guys.

I've trolled around the net looking at various DLL tutorials, but they aren't really helping me (they talk about how to use LoadLibrary() and GetProcAddress(), this is stuff I already know). I need to go deeper than that. And I'm not finding squat :)

I know how to get the exe (the engine) to communicate to the DLL. I've got that going through an interface defined by an abstract base class, which is inherited by all the plugins. No problem there. What's giving me issues is going the other way, from the DLL to the engine.

So here is the setup. I have the exe part of the project, which is the engine. I am writing a system for plugins (which are basically DLLs that add functionality to the engine for use by the game designers, but which can be omitted from the game's release package, because they are of no use to the players). So let us say there are roughly 15 or 20 plugins.

Each plugin has a standard interface by which the engine can access the functionality of the DLL (the interface being enforced by the abstract base class defined in the engine code). There will only be a few functions in the interface, but all plugins will be required to implement them. Okay? Pretty standard stuff, I think.

Here are the requirements for the DLLs that I'm having some trouble with:

In the engine part, I would like to have (let's say) around 200 functions or so available for use by the DLLs. These are not global functions, they are functions within classes (so yes, we will need instances of those classes in the DLL). There are also a handful of global variables (instances of manager classes) in the engine that the DLLs will need access to (things like MemoryManager, GraphicsManager, TimeManager, and so forth). I guess the 200 functions needed by the DLLs would all be members of those classes (or subclasses thereof). Finally, the DLLs will need to be able to instanciate some classes defined in the engine (as previously stated). These are container and math classes meant for general use. Things like String, LinkedList, Vector3D, and so forth. It should be noted that some of these classes contain templates (especially the containers).

Quite clearly (I think), I don't want to have to GetProcAddress() on the 200 functions in the engine from each of the plugins (times 20ish). If that can be avoided, that would be great

So, as an example (a plugin I have partially completed), this might be part of the header for a plugin (DLL)

#include "EngineBase.h"
#include "PluginManager.h"

class FontBuilder : public PluginBase
virtual ~FontBuilder();

String* GetName();
void Execute();

void BuildFont();

String Name;
Bitmap FontBitmap;

Okay? The interface is only two functions (at this point). PluginBase is my abstract base class defined in the engine itself which enforces the interface.

Notice already I want to use the String class in the interface. This class is defined in the engine, and contains templated functions (and boy does the complier hate that!). I'm also using String and Bitmap classes here (also defined in the engine).

In the code (which I haven't written yet, so I'm just making this up as an example), I might want to do stuff like this:

void FontBuilder::BuildFont()
unsigned int Timer;
String NameHolder;

NameHolder = Name;
Timer = TimeManager->CreateCountUpTimer();

Okay, obviously that is not real functionality, I'm just making it up to show things that might need to be done inside of DLL code. 1) It needs to access class instances globally defined in the engine (e.g. TimeManager), 2) Create instances of classes that are defined in the engine (e.g. String).

I hope that makes sense what I'm after here. While I am by no means a new programmer (I've been doing this for over 20 years, actually closer to 30 now that I think about it), this is a new area of coding for me. So feel free to tell me if what I need here is totally impossible, or if the answer is completely obvious, or whatever. Any advice that is given on how to properly set this up would be a big help to me.

Thanks, Ron

Share this post

Link to post
Share on other sites
Guest God Almighty
You could try linking the DLL against the application (which of course would need to export the requested symbols). But since Windows is a bit peculiar when it comes to dynamic linking, this might not work. In that case, you could try moving all the symbols needed by your plugins to another DLL which in turn would be used by the plugins, like this:

game.exe => plugin1.dll => base.dll
=> plugin2.dll => base.dll

Hope that helps,

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this