Advertisement

globals and DLL problem

Started by May 23, 2001 12:49 AM
6 comments, last by SCRUB 23 years, 8 months ago
Hi there , Im having trouble with my DLL. I built a particle engine with loads of effects and it has basic collision detection in it. One of the effects is Sparks which incorporates this collision detection. It is a Ray class that sees if a Ray has Intersected with any polygons in my GLOBAL WorldManager. In my DLL , I can create a DLL fine with all the no collision detection with them. But becuase Sparks uses Ray that verifys off a "Global" WorldManager i am having linker errors. The errors are because in "Sparks" WorldManager is declared as an extern e.g extern WorldManager world; then I use world in My sparks code. Normally I would have WorldManager declared in Main.cpp But how would I get the DLL to understand to take in an imported global WorldManager. I hope you can see my dilema I would really appreciate some help(as you can see im probably breaking the no. 1 rule of dlls or something). Thanks el_scrub
LE SCRUB
I am assuming that WorldManager is in your DLL, and Sparks is in your main (exe)?? If so, try this...

In your DLL, set up some sort of header like the following:

#ifndef ENGINE_H#define ENGINE_H#ifdef ENGINE_EXPORTS  #define ENGINE_STUFF __declspec(dllexport)#else  #define ENGINE_STUFF __declspec(dllimport)#endif #include "World.h"#include "Others.h"ENGINE_STUFF WorldManager GWorldManager;#endif //ENGINE_H//Then, somewhere in your executables code, besides linking //to the Engine.lib (in your project settings if you are //using MSVC)#include "Engine.h"class Spark{public:  Spark() {GWorldManager.DoSomething;}}; 


Hope this helps? This is also assuming you are developing on/for Windows.

Mainly, if you need more info, look up the __declspec keyword in the MSDN documentation.

-mihkael
Advertisement
ok I did that , what i am getting now is

"explosion.obj : error LNK2005: "class WorldManager world" (?world@@3VWorldManager@@A) already defined in basicparticle.obj"

I have basicparticle.cpp , its header is in particle.h
all of my effects headers are in particles.h

I put the global -> ENGINE_STUFF WorldManager world
in there could that be confusing things ?



p.s I have the class declared as
class ENGINE_STUFF WorldManager

and it is defined for ENGINE_EXPORTS
LE SCRUB
If I put this declaration directly into sparks it will
get rid of the linker errors.

But ...when I try and run a program to use Sparks I get linker errors trying to import an "unresolved external symbol" WorldManager ...and all its functions

!!!!

You''re probably trying to access a class funktion that''s in the .exe... that''s kinda impossible to do.. class funktions use a NEAR pointer instead of a FAR pointer (speed reasons) and you gotta define your class funktions as __stdcall oder something like that.. haven''t got that worked out either... But I think I''ll go another way so that it might be possible to port it to linux.

cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
Okay, here try this... This is a ''snippet'' of code from something I was doing.... Hopefully it will help you figure out your problem.

As a prelude, know that I have this part of my project broken into 2 things...

ENGINE.DLL
GAME.EXE

The first stuff here is in the ENGINE project..

//FILE: Engine/EngineHeader.h#ifndef ENGINEHEADER_H#define ENGINEHEADER_H#ifdef ENGINE_EXPORTS#define ENGINE_STUFF __declspec(dllexport)#else#define ENGINE_STUFF __declspec(dllimport)#endif#include "Timer.h"#endif //***********************NEXT FILE*************************//FILE: Engine/Timer.h#ifndef TIMER_H#define TIMER_Hclass ENGINE_STUFF Timer{public:	Timer(){startTime = 0;}        DWORD GetDuration() {return 0;}	virtual ~Timer(){}	//Various Other functions that aren''t relevant...protected:	DWORD startTime;private:};ENGINE_STUFF extern Timer GTimer;#endif //TIMER_H//*********************NEXT FILE*****************************//File: Engine/Timer.cpp#include "CoreHeader.h"  //That was the 1st file I had up there.ENGINE_STUFF Timer GTimer;//***********************************************************//      NOW FOR THE GAME (EXE) PROJECT//***********************************************************#include "EngineHeader.h"void TickEngine(){	RFLOAT deltaTime;	deltaTime = GTimer.GetDuration();	GTimer.BeginTimer();} 


Hopefully that helped clear up any confusion. If you just stick your code in place of mine (replace my timer with your world manager, and your sparks code with the TickEngine function stuff), you should be all good. Note that; if you have your WorldManager defined in your executable, and your DLL is where your sparks are, that WON''T. You''ll have to re-think the logic to either get them reversed, or in the same (either both in same DLL, sparks in EXE that uses the DLL where WorldManager is. Good luck!

-mihkael
Advertisement
Yes that worked Fucking Excellently

I LOVE YOU MAN, I REALLY LOVE YOU.

I cannot express how much, but its a lot.

Mucho oblidged for all the Information and all the help. You didnt have to , but you did , and I really respect that.

thanks again.

Karl
LE SCRUB
Hey, no prob. Glad I could help you out. I remember when trying to learn all the problems with using DLL''s, I had a heck of a time, so I understand.

Take care, and good luck with your stuff!
-mihkael

This topic is closed to new replies.

Advertisement