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;
}
IIR_Library.def
LIBRARY "IIR_Library"
DESCRIPTION 'IP Independant Renderer'
EXPORTS
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";
return;
}
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.
theclass.draw();
}
Shared File
IIR.h:
struct testpt
{
virtual void draw(void) = 0;
};
class test : public testpt
{
private:
public:
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]