Jump to content
  • Advertisement
Sign in to follow this  
eGamer

dll usage

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

suppose i have a .dll file and i want to use it in my project. my old way is to extract a .lib file and use the dll through it and a header file previously found. what if there is no header file for the dll is there a way to extract a header file for a dll , or is there a direct way to use .dll classes and functions without header, please help...?

Share this post


Link to post
Share on other sites
Advertisement
If you have no header then you probably won't be able to use the DLL unless it's a COM DLL that implements IDispatch or something like that. You can see what symbols it exports with dumpbin or a similar program, but that would only tell you what fuctions it has, but not how to call them or even how many parameters each function takes.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
On Win32 you can use LoadLibrary() to access a DLL and all functions. Although you wouldn't normally be able to access classes directly (becuase of class name mangling), rather you would go through some kind of static factory function. You can then call GetProc() to get a pointer to a function.

BTW: If you have Microsoft Visual C++, you can use the depends DLL to get all the exposed function / class names in a DLL.

Mr. Creamy.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
On Win32 you can use LoadLibrary() to access a DLL and all functions. Although you wouldn't normally be able to access classes directly (becuase of class name mangling), rather you would go through some kind of static factory function. You can then call GetProc() to get a pointer to a function.

BTW: If you have Microsoft Visual C++, you can use the depends DLL to get all the exposed function / class names in a DLL.

Mr. Creamy.



so if i have the dll file i can use its functions...
well i know previously all the classes prototypes and i know its description,
could give me an example of loading a dll and then using getProc to access the
methods or classes?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
If you have no header then you probably won't be able to use the DLL unless it's a COM DLL that implements IDispatch or something like that. You can see what symbols it exports with dumpbin or a similar program, but that would only tell you what fuctions it has, but not how to call them or even how many parameters each function takes.



well the project that has produced the dll has a lot of headers and i wanted to get rid of re-including them in another projects with the dll so is there
a way ( from the project source code ) to combine those headers to one header
without manually merging the headers into one.

Share this post


Link to post
Share on other sites
You can write an Interface/API class that you Export into the application that is calling the DLL. Let's say that you have a OpenGL renderer and you wish to export it so that you can use the renderer in more than one program. You create a base class, IVideoDevice and store that header file so both the DLL and the application can access it.

Here's an example of what my IVideoDevice object looks like:

// <summary> interface for the video device that we'll be returning from
// the plugin system. Allows us to have a simple API for both renderers </summary>
class IVideoDevice
{
public:
// constructor/destructor
IVideoDevice(void)
{
m_bFullscreen = false;
m_iHeight=m_iWidth=m_iBpp=0;
}

// API virtual methods
virtual bool Init(void)=0;
virtual int GetDriverID(void)=0;
virtual void DrawScene(void)=0;
virtual void DeInit(void)=0;
protected:
// members
bool m_bFullscreen;
int m_iHeight;
int m_iWidth;
int m_iBpp;
};



Now that header file is included for both the Application and the DLL. Make all the methods pure virtual ( virtual void Method(void) = 0; ) so that you are forced to implement them on the DLL side. This is what my OpenGL class looks like:

class GLDevice : public IVideoDevice
{
public:
// constructor/destructor
GLDevice(void);
~GLDevice(void);

// API virtual methods
bool Init(bool,int,int,int);
void DeInit(void);
int GetDriverID(void);
void DrawScene(void);

private:
// methods
void ResizeWindow(int,int);
void SetupWindow(void);
};



Now you Export it like you would with any normal function, this is how I export the OpenGL class from the DLL which then is typecasted into an IVideoDevice pointer (that the application can handle):

GLAPI_EXPORT IVideoDevice* ExportAPI(void)
{
return new GLDevice();
//pDevice = new GLDevice();
}



I hope this helps! You're always going to need some sort of header file when you're exporting classes from a DLL. Because the way this method is setup, you won't get errors about methods not being implemented in the application (because all method calls are virtual to the application). I've never used COM, so I'm not sure how that works, but I've designed my LibraryManager around the fact that I eventually want to be able to have cross-platform DLLs that can be used in Linux.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!