Sign in to follow this  

Adding Games Through DLL

This topic is 3591 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

Im working on a gaming client and I want to be able to add games to the client through dlls. For example to add a game to the client all the user needs to do is load the appropriate dll and you can play pac man. The game client would be using OpenGl and SDL so I need to run graphics,input and sound functions from dlls.

Share this post


Link to post
Share on other sites
Quote:
Original post by Supaflyfrank
Im working on a gaming client and I want to be able to add games to the client through dlls. For example to add a game to the client all the user needs to do is load the appropriate dll and you can play pac man. The game client would be using OpenGl and SDL so I need to run graphics,input and sound functions from dlls.

Uhm, Okay. And your question is ?

Share this post


Link to post
Share on other sites
From a design perspective your core client could contain an interface pointer for example IPlugIn which has methods such as IPlugIn::Run(). When the DLL is loaded at runtime your core application would then obtain a handle to an object within the DLL which inherits from the IPlugIn class:

class CPacMan : public IPlugIn
{
};

So, your core client would execute the basic steps below:

1) Create a pointer of type IPlugIn
2) Load the DLL
3) Call into the DLL to return a pointer to a function to create the object (you can't just export the class)
4) Call the Run() method on the returned object and have the DLL handle all game logic


class IPlugIn
{
public:

IPlugIn( void );
virtual ~IPlugIn( void );

virtual void Run( void ) == 0;
};

// this would be defined in your DLL
__declspec( dllexport ) CPacMan* CrateLogic( void )
{
return new CPacMan();
}

// so would this
class CPacMan : public IPlugIn
{
CPacMan( void );
virtual ~CPacMan( void );

virtual void Run( void );
};

int main( void )
{
// define a pointer to the IPlugIn interface
IPlugIn* pGameLogic;

// go through all your steps here to load the DLL of choice

// obtain a handle to the DLLs "CreateLogic" method for example

// obtain a pointer to the CPacMan object
pGameLogic = (IPlugIn*)(DLL function here)

// run the logic
pGameLogic->Run();
};






This of course isn't perfect but just something to think about if nothing else.

Share this post


Link to post
Share on other sites

This topic is 3591 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.

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