Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Loading DLLs at Runtime

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

Hi, I asked about this sometime before christmas but its gone now so I'll have to make this new thread. I was trying to load a DLL at runtime, and get a class from that DLL, then use it as if it was defined in the program itself rather than in the external DLL. Several people offered help on this, thanks for that, and I tried what you suggested, but I still cant quite seem to make it work. Here is what I have, prehaps you can see something I havent done, or have done wrong There are two separate VC6 projects, one for the DLL and one for the program: Project IIR_Library IIR_Library.cpp:
#include <iostream.h>
#include "iir.h"

testpt* getclass (void);

void test::draw(void)
	cout << "\n\nIT WORKS!\n";

testpt* getclass (void)
        return (testpt*) new test;
LIBRARY      "IIR_Library"
DESCRIPTION  'IP Independant Renderer'

getclass      @1
Project IIR_Program IIR_Program.cpp:
#include <windows.h>
#include <iostream.h>
#include "..\IIR_Library\iir.h"

void main (void)
	HINSTANCE thelib;
	testpt* theclass;

	cout << "Searching for IIR_Library.DLL... ";
	thelib = LoadLibrary("iir_library");

	if (thelib==NULL)
		cout << "Not found\n"; 

	cout << "\nUsing getclass() to return pointer to renderer...\n";
        theclass = (testpt*)(GetProcAddress(thelib, "getclass")());

	cout << "Returned from getclass(), renderer is apparently at " << &theclass << "\n"; 
	cout << "Calling member function draw()...";

	// Following line produces the error :

	//		error C2228: left of '.draw' must have class/struct/union type

	// Also tried using "test* theclass" instead of "testpt* theclass" and getting getclass() to return a "test*",

	// but this results in exactly the same thing.

Shared File IIR.h:
struct testpt
	virtual void draw(void) = 0;

class test : public testpt
	virtual void draw(void);
This might not be quite right, I have been playing with it a bit and I dont have VC installed right now (a job for thursday), but thats what the files are currently. Hope someone can help me. Also if anyone else has done something similar prehaps they could share this with me? Thank you, Ashley

Warning in life.cpp (8): const Happiness is declared but never used.
EDIT: Messed up the source text box thingies EDIT 2: Uh, all the includes seem to have gone in one big line unexplainably. Its not like that in the source files obviously EDIT 3: Editing this message messes it up [edited by - allsorts46 on January 21, 2003 5:10:10 PM] [edited by - allsorts46 on January 21, 2003 5:12:24 PM] [edited by - allsorts46 on January 21, 2003 5:15:51 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
a pointer is a variable which contains the address of data. The . operator increments in memory to the location of the member you''re accessing, of a typical structure. i think. it makes sense anyway. With a pointer, it only is using 4 bytes of memory, but points to another location which actually contains the actual declared structure object thingie. So you can''t use ., you use ->, which goes to the new memory location.

struct FOO
int a;
int b;

FOO bob;
bob.a = 1;

FOO * pbob = new FOO; //Allocate a FOO
pbob->a = 1; //Dereference pbob, accessing a

i guess i think it looks like this in memory:
bob[ aaaa bbbb ] a takes up four bytes, so does b
where as
pbob[ #### ] four bytes which point to..
####[ aaaa bbbb ] lol, i guess that''s good enough...

sorry if i confuse and screw you up more.

Share this post

Link to post
Share on other sites

  • 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!