Skip to main content
gamedev.net
🔒 Locked

DLLs and Class Pointers...

Started by Richy2k Jan 12, 2005 at 6:08 PM 3 replies 450+ views
Original Post
Richy2k
Richy2k
Straight to the point, I have a DLL, inside it functions will be stored that can access classes within the EXE. To do this im guessing that the system must work like this: EXE calls a function inside the DLL to set a pointer DLL sets its pointer to the class(es) EXE then calls (for example) the update function within the DLL DLL does the dirty work, and can call functions within the EXE via this pointer. Im having a few problems compiling the DLL though: engdll.obj : error LNK2001: unresolved external symbol "public: void __thiscall cTestClass::PrintFloat(float *)" (?PrintFloat@cTestClass@@QAEXPAM@Z) engdll.obj : error LNK2001: unresolved external symbol "public: void __thiscall cTestClass::PrintInt(int *)" (?PrintInt@cTestClass@@QAEXPAH@Z) engdll.obj : error LNK2001: unresolved external symbol "public: void __thiscall cTestClass::PrintText(char *)" (?PrintText@cTestClass@@QAEXPAD@Z) Does anyone else have any experience with DLLs, this is my first attempt at making one and i've probably went about this completely the wrong way. Anyways, here is the code i'm using to make the DLL (condensed all the includes so its one file for on here), its not got any practical use, its just a mess about for now: engdll.cpp:

class cTestClass
{
public:
	void	PrintText(char *l_szText);
	void	PrintInt(int *l_iNumber);
	void	PrintFloat(float *l_fNumber);

};

cTestClass	*g_pEngine;

void	InitDLL(cTestClass *l_pTestClass)
{
	g_pEngine = l_pTestClass;
}

void	UpdateDLL()
{
	int i = 8;
	float f = 0.08f;
	g_pEngine->PrintText("Hello, World");
	g_pEngine->PrintText("The number 8:");
	g_pEngine->PrintInt(&i);
	g_pEngine->PrintText("The number 0.08:");
	g_pEngine->PrintFloat(&f);
}

void	CloseDLL()
{
	g_pEngine = 0;
}

engdll.def:

EXPORTS
		InitDLL
		UpdateDLL
		CloseDLL

SiCrane
SiCrane
Show the class definition for the class you're trying to pass. Specifically, are you using virtual functions for PrintFloat(), etc.?
Richy2k
Richy2k
/me embarassed, it compiles when i declare the functions as virtual.

And it works! Thanks for the help, only problem is with the numbers, but thats easily sorted, current output from my test program:

Hello, World
The number 8:
006AFD9C
The number 0.08:
006AFD98
Press any key to continue
xiuhcoatl
xiuhcoatl
I am not entirely sure here but I think you may be going about establishing your dll incorrectly.

While the DLL is just a shared library it does need to be loaded into system memory so the OS needs to understand how to load it into memory, map the functions and then hand it back to you. So there are some standard entry points that you need to provide for this to work.

Here is a grat PDF that explains DLLs in detail and will probably get you on the right path...

http://iaci.unq.edu.ar/materias/Inst_avanz/Dll/

and click on the "DLLs for Beginners.pdf".


Hope that helps..


#dth-0


"C and C++ programmers seem to think that the shortest distance between two points is the great circle route on a spherical distortion of Euclidean space."Stephen Dewhurst

Topic Locked

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

Sign in to reply to this topic.