Advertisement

Problems using DLL files

Started by November 23, 2000 03:53 PM
1 comment, last by Kosh 24 years, 2 months ago
hi everyone, ok, I recently up till now, used static libs to partition off code that I wanted to keep in a library, then I''d link it in with my executables, just like everyone does...which worked fine.. yesterday, I got some tutorial code from a friend on how to use DLL''s and well, I implemented it instead of exporting class definitions from the dll, I resorted to exporting a function, which would create the object for me, returning me a pointer to it. This pointer is a base class pointer, since my library is to do with DirectX. So by using this technique, I could just link with OpenGL dll and it should work fine. Everyone knows about that technique, or you should do anyway, cause it rules. I have these classes in my dll DXGraphics DXSurfaceManager DXSpriteManager now, DXGraphics uses a DXSurfaceManager object to maintain it''s list of flipping surfaces also, DXSpriteManager uses a DXSurfaceManager object to maintain it''s list of sprites DXGraphics seems to execute fine. but DXSpriteManager doesnt the constructor is like this DXSpriteManager::DXSpriteManager(Graphics2D *gfx_object,char *logfilename): SpriteManager(logfilename) { //#if defined _DEBUG logfile << "TRACE-> DXSpriteManager::DXSpriteManager(Graphics2D *, char *)" << endl; //#endif logfile << "assigning gfx object" << endl; gfx = (DXGraphics2D *)gfx_object; logfile << "Creating a surface manager for the sprite manager object" << endl; surface_manager = new DXSurfaceManager(gfx->GetDirectDrawObject(),logfile); logfile << "everything ok, returning" << endl; } Where Graphics2D * is a parent class of DXGraphics, it has a pure virtual class beneath is IGraphics, which is just a shell, I should remove that, since it does nothing really... but anyway.... the logfile is of type ofstream and it''s used to write a logfile of whats going on in my code. everything works fine, the DXGraphics object is constructed and a Graphics2D pointer is returned to the application that pointer is then pushed into the creation of the DXSpriteManager object, now, as you can see surface_manager = new DXSurfaceManager(gfx->GetDirectDrawObject(),logfile); that should use the Graphics2D * to call it''s GetDirectDrawObject function, which returns a IDirectDraw7 * back, so that it can be passed into the constructor, logfile is passed in as a ofstream & but the code stops here, just quits...When I debug it, the debugger stops and just doesnt do anything, doesnt tell me anything, doesnt give any errors, nothing so, you can see, my problem, thanks if you can help me, it would be great cya ! kosh
if understanding it made and born with time, then time, is understandings greatest enemy.....
hi everyone,

ok, I narrowed this down, in the constructor for the DXSpriteManager object I say this


gfx = (DXGraphics *)gfx_object;


where gfx is defined within the DXSpriteManager class like so:-


DXSpriteManager: public SpriteManager
{
protected:
DXGraphics2D *gfx;

etc,etc
};


now, when I say the first code segment in this message, you should think that would be ok, but it''s not, if I remove the gfx pointer from the class and make it local to the function, alike this


DXSpriteManager::DXSpriteManager(Graphics2D *gfx_object, char *logfilename="DXSpriteManager.log")
{

DXGraphics2D *gfx = (DXGraphics2D *)gfx_object;

etc etc
}



everything works fine..as you can see from this portion of the DXSpriteManager.log file

The DXSpriteManager constructor object in full


DXSpriteManager::DXSpriteManager(DXGraphics2D *gfx_object,char *logfilename): SpriteManager(logfilename)
{
//#if defined _DEBUG
logfile << "TRACE-> DXSpriteManager::DXSpriteManager(DXGraphics2D *, char *)" << endl;
//#endif

logfile << "assigning a temp DXGraphics2D pointer" << endl;
DXGraphics2D *gfx = gfx_object;
logfile << "assigning gfx object" << endl;
logfile << "gfx_object = " << gfx_object << endl;
//gfx = gfx_object;
logfile << "gfx = " << gfx << endl;
logfile << "getting a dd7 object" << endl;
IDirectDraw7 *dd7 = gfx->GetDirectDrawObject();
logfile << "Creating a surface manager for the sprite manager object" << endl;
surface_manager = new DXSurfaceManager(dd7,logfile);
logfile << "everything ok, returning" << endl;
}


The DXSpriteManager.log file thats written to the disk


TRACE-> SpriteManager::SpriteManager(char *)
TRACE-> DXSpriteManager::DXSpriteManager(DXGraphics2D *, char *)
assigning a temp DXGraphics2D pointer
assigning gfx object
gfx_object = 0x00970050
gfx = 0x00970050
getting a dd7 object
Creating a surface manager for the sprite manager object
TRACE-> DXSurfaceManager::DXSurfaceManager(IDirectDraw7 *, ofstream &)
everything ok, returning
TRACE-> DXSpriteManager::~DXSpriteManager()
TRACE-> DXSurfaceManager::~DXSurfaceManager()


Now, if I remove the local DXGraphics2D and rely on the class version again, remembering this is all inside the class, it worked in static libs, it just doesnt work in dll files, for some reason, I get this

The constructor again


DXSpriteManager::DXSpriteManager(DXGraphics2D *gfx_object,char *logfilename): SpriteManager(logfilename)
{
//#if defined _DEBUG
logfile << "TRACE-> DXSpriteManager::DXSpriteManager(DXGraphics2D *, char *)" << endl;
//#endif

logfile << "assigning a temp DXGraphics2D pointer" << endl;
// DXGraphics2D *gfx = gfx_object;
logfile << "assigning gfx object" << endl;
logfile << "gfx_object = " << gfx_object << endl;
gfx = gfx_object;
logfile << "gfx = " << gfx << endl;
logfile << "getting a dd7 object" << endl;
IDirectDraw7 *dd7 = gfx->GetDirectDrawObject();
logfile << "Creating a surface manager for the sprite manager object" << endl;
surface_manager = new DXSurfaceManager(dd7,logfile);
logfile << "everything ok, returning" << endl;
}


The logfile output


TRACE-> SpriteManager::SpriteManager(char *)
TRACE-> DXSpriteManager::DXSpriteManager(DXGraphics2D *, char *)
assigning a temp DXGraphics2D pointer
assigning gfx object
gfx_object = 0x00970050


weird !!!! anyone help me out? thanks...

if understanding it made and born with time, then time, is understandings greatest enemy.....
Advertisement
hi everyone, this is an update on my situation, for anyone reading this, if anyone...

in the DXSpriteManager constructor, the assignment of gfx_object to gfx, alike:


gfx = (DXGraphics2D *)gfx_object;


where gfx is a protected member of the DXSpriteManager class and is defined as


DXGraphics2D *gfx;


and gfx_object is of type Graphics2D *, which is a parent class to DXGraphics2D is passed into the constructor, like


DXSpriteManager::DXSpriteManager(DXGraphics2D *gfx_object,char *logfilename): SpriteManager(logfilename)


the assignment works fine, but any attempt to use the pointer results in


First-chance exception in Zargadia_debug.exe (NTDLL.DLL): 0xC0000005: Access Violation.


ARGGGH !!! fucking dll''s pissing me off already !

can anyone help? is anyone reading this? or am I just being ignored

kosh


if understanding it made and born with time, then time, is understandings greatest enemy.....

This topic is closed to new replies.

Advertisement