Jump to content
  • Advertisement
Sign in to follow this  
demize

Extensions

This topic is 3794 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would like to have purchasable extensions for game I'm currently making. Not the kind that users could make, but a dll that a user can buy and put in the game folder. The game would be looking for these dlls, and if they were there, it would let the game do more things. I'd like for the game to not include these functions, but if it has to, I'll use a different way of doing it. I'm also using C++, btw.

Share this post


Link to post
Share on other sites
Advertisement
The part where I make the dlls containing game data and make the game search for them.

Share this post


Link to post
Share on other sites
You can use FindFirstFile()/FindNextFile() to search the directory for DLLs. To make the DLLs function within the game you need to create a specification for what functions those DLLs will export and what each of those functions will do. For example, let's say your game is a space game and your extensions are different ships that the player can play. The functions your DLL might export are something like

bool Initialize() - initializes the ship
unsigned long GetMaxSpeed() - gets the maximum speed of the ship
unsigned long GetAcceleration() - get the acceleration of the ship

To load and use the extension, you load the DLL using LoadLibrary() and then get addresses to these three functions using GetProcAddress(). If all three of those functions exist then the DLL is a new type of ship.

If you want to support different types of extensions you might require your DLLs to export a function like GetType() which will tell you what type of extension the DLL represents and therefore determine which other functions you can expect the DLL to export.

Share this post


Link to post
Share on other sites
use boost::filesystem if you can, it will save you alot of work!

additionally, have you investigated using a scripting language? just a suggestion, as its not suitable in all situations.

I would also recommend reading a few post on gamedev about plugin architectures as it's been covered quite a bit on these forums.

Share this post


Link to post
Share on other sites
Quote:
Original post by Colin Jeanne
You can use FindFirstFile()/FindNextFile() to search the directory for DLLs. To make the DLLs function within the game you need to create a specification for what functions those DLLs will export and what each of those functions will do. For example, let's say your game is a space game and your extensions are different ships that the player can play. The functions your DLL might export are something like

bool Initialize() - initializes the ship
unsigned long GetMaxSpeed() - gets the maximum speed of the ship
unsigned long GetAcceleration() - get the acceleration of the ship

To load and use the extension, you load the DLL using LoadLibrary() and then get addresses to these three functions using GetProcAddress(). If all three of those functions exist then the DLL is a new type of ship.

If you want to support different types of extensions you might require your DLLs to export a function like GetType() which will tell you what type of extension the DLL represents and therefore determine which other functions you can expect the DLL to export.


How would I use the functions from each dll? Would I have to load them one by one, or could I just load them all?

Share this post


Link to post
Share on other sites
two ways, have a hard coded list of methods which you expect a DLL to implement and use GetProcAddress to fetch function pointers.

2ndly you can parse the export table of the DLL and try to get the methods read in that way (but this is hard to do well, you need to convey type information so you can use the right function pointer types inside the app)

Share this post


Link to post
Share on other sites
Quote:
Original post by demize
How would I use the functions from each dll? Would I have to load them one by one, or could I just load them all?

The documentation for GetProcAddress() has some example code you might find useful. You will also need to load each function individually (there is no "batch-load").

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!