Modular app design
Ok, I've got a question about making modular applications. At least that what I call them. Basically, I have a bunch of classes, or rather just headers. Now for the implementations, I want to be able to create multiple implementaions of any class, and not have to recompile the whole program. So basically, say I have a class cWindowMaker. It has a Create_Window(x, y, width, height) function, and maybe some callbacks, but lets say it just has the Create_Window function. Now, I make an implementation that basically creates a window with all the bells and whistles, like the title bar, all the titlebar buttons, resizable, etc. And then I somehoe compile that implementation in a DLL file. Then, I load that DLL dynaically, create an instance of the class and call my Crete_Window function. Now, imagine I make another implementation, that basically makes a window without anything, no border etc. Make another DLL and now I want to use it. Well, obviously I jus have to replace the old DLL and restart my app and voila. The hard part? HOW do I make all that work?? Can't wrap myu head around it. Can anybody please help? Im sure this kind of stuff has been done by somebody here before...
Thanks in advance,
Anton.
Research: abstract base classes, interfaces, and polymorphism.
Once you're familiar with that, do this:
Make your EXE load a DLL and call a "pre-shared name" DLL function that returns a pointer to the base class. The DLL can create any kind of derived class it wants to. As long as there are virtual functions, the pointer that the DLL returns will have a vtable that accurately points to the functions in the DLL.
You can use LoadLibrary and GetProcAddress to do the DLL loading and function-finding on the fly without restarting your EXE (but you will still have to recompile any new DLL you want to use).
Once you're familiar with that, do this:
Make your EXE load a DLL and call a "pre-shared name" DLL function that returns a pointer to the base class. The DLL can create any kind of derived class it wants to. As long as there are virtual functions, the pointer that the DLL returns will have a vtable that accurately points to the functions in the DLL.
You can use LoadLibrary and GetProcAddress to do the DLL loading and function-finding on the fly without restarting your EXE (but you will still have to recompile any new DLL you want to use).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement