Need someone familiar with DLLs
Hello everyone. I'm not sure exactly where to post this as it is kind of a generic question yet is related to (game programming + win32 + c++) so I just posted here.
I've never written a DLL before and after searching the board and the web I'm thinking about using them for a program I'm writing. From someone who has used DLLs I just wanted some input as to whether what I'm doing is stupid/mis-usage of DLLs or not.
My program:
- A win32 app. that will have a bunch of different card games built into it.
- The user will select a specific game from a dialog box.
- At this point I'm thinking about loading a DLL containing that game's code (Ex: Solitaire.dll; or BlackJack.dll; etc..)
- This will allow me to keep my main program small & clean; permit easy upgrading/altering of my code later (adding more game functionality;etc.).
Uh, is this a good usage of DLLs? For every new game I would of course add another DLL. Is this overkill? or okay? Basically every game DLL would have similar functions just different implementations
Ex:
Code:
// Solitaire.dll
void handleMouseClicks(...){};
bool draw(...){};
Code:
// BlackJack.dll
void handleMouseClicks(...){};
bool draw(...){};
Code:
//Main pseudocode.
if(SOLITAIRE)
Load(Solitaire.dll);
else if (BLACKJACK)
Load(BlackJack.dll);
WM_LEFTMOUSEDOWN:
handleMouseClicks(...); // Call specific function depending on which game DLL is loaded. I'm assuming this would work???
break;
This a bad idea? Or should I just go statically with a class Hierarchy?
ex:
Code:
class Game
{
virtual void handleMouseClicks(...){};
virtual bool draw(...){};
}
class Solitaire:Game
{
}
class BlackJack:Game
{
}
int main()
{
Game *currentGame;
if(SOLITAIRE)
currentGame = new Solitaire();
else if (BLACKJACK)
currentGame = new BlackJack();
WM_LEFTMOUSEDOWN:
currentGame->handleMouseClicks(...); // I'm assuming this would work??
break;
}