Skip to main content
GameDev.net gamedev.net
🔒 Locked

DLL Question

Started by bkt Mar 10, 2004 at 11:44 AM 6 replies 1.2k views
Original Post
bkt
bkt
I use the normal method (atleast normal for me) of loading DLL files. That would be loading it through HINSTANCE and then using LoadLibrary and using GetProcAddress to grab a function. I ran into a stall, I need to load classes from DLLs (basically, the whole DLL class structure into my program) as well as anything else within the extern "C++" line. How would I go about doing this without using "GetProcAddress?" I''m currently using extern "C++" __declspec(dllexport) : I know I must include the header file for DLL inclution, but would I need to use __declspec(dllimport) instead? Any help would be great.
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]
bkt
bkt
*bump*
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]
SantaClaws
SantaClaws
The way this is often done with basic DLL functionality is by creating a set of interface functions that you can call that will return an address to the instantiated classes in your DLL process.

So, for instance, you could have a function called "Initialize" in your DLL. When you loaded the DLL, you would GetProcAddress on that and call the Initialize function. The initialize function could return something like the following:
struct exportedData_t
{
class1_t *class1;
class2_t *class2;
// etc
};

You'd allocate and set the values of that structure in the DLL, the return it to the host to do what it pleases with it.

[edited by - SantaClaws on March 10, 2004 6:23:48 PM]
bkt
bkt
I was scrolling through some of the previous topics on this, someone suggested using a "pluggable factory?" (did I get that right?). I''m going to need to be able to do this with several DLLs... my current structure is:

CoreEngine.dll -- OpenGL.dll
|
DirectX.dll

etc, etc.

I''ll have about 5 DLLs in total probably.
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]
bkt
bkt
*bumpppy*
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]
pegasus123
pegasus123
Not sure if the ffg is what u want ...

To get a class from a DLL.
..................................................
// - THEDLL.dll

// - Global class ptr within the dll
CMyClass* g_pClass = NULL;

__declspec(dllexport) HRESULT DllGetClass(CMyClass** ppObj)
{
if (!ppObj)
{
// - Pointer to nothing. SCREAM AND SHOUT !!
assert(0);
return E_FAIL;
}

// - Do we have an instance of our class yet ??
if (!g_pClass)
{
g_pClass = new CMyClass;
}
*ppObj = g_pClass;
return S_OK;
}

McZ
McZ
I have a plugin RenderCore for my rendersystem that is either OpenGL or Direct3D.. I have created an abstract class that the two API''s is derived from

e.g.
Abstract base class

class cRenderCore {

// some internal member stuff


protected:

// some shared internal stuff


public:

cRenderCore() {};
virtual ~cRenderCore() {};

/**
Create(HWND)
this will create the rendering context in the passed in window
*/

virtual void Create(HWND hWnd) = 0;

/**
BeginFrame()
Clears the screen, reset the world matrix etc.
*/

virtual void BeginFrame() = 0;

/**
EndFrame()
Flips the backbuffer
*/

virtual void EndFrame() = 0;

/**
RenderBuffer(cVertexBuffer *vb)
Renders my unified vertexbuffer
*/

virtual void RenderBuffer( cVertexBuffer *vb ) = 0;

// more virtual functions goes here

// like set material, light etc.

...
...
};


so then in my app where I want to use my rendersystem I do like this

HWND hwnd; // the window handle

cRenderCore *RenderCore = NULL;

void InitRenderer()
{
RenderCore = LoadRenderCore( "RenderCoreGL.dll" );

RenderCore->Create( hwnd );
}

// render loop

do{
...

// render a vertex buffer

RenderCore->BeginFrame();
RenderCore->RenderBuffer( vb );
RenderCore->EndFrame();

}while(1);


the ''LoadRenderCore( char *FileName );'' function loads a .Dll file and achives an function using ''GetProcAddress'' then it will call that function wich will return the API implementation of the abstract RenderCore class
bkt
bkt
That's exactly what I want to do.

Do you return the "RenderCore" object with that Load Function? (or return a function that creates the object?)

[edited by - bkt on March 11, 2004 3:14:20 PM]
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.