Advertisement

run time dlls

Started by March 03, 2001 06:57 AM
3 comments, last by Noodles 23 years, 10 months ago
Hi, I was prototyping my engine, but i get an error appears and I don''t know why. I got an engine class in a dll (engine.dll) that is loaded at load time in the main executable (launch.exe) via a .lib file. Now the engine class contains a pointer to an abstract base class called ''rendrv'' and several functions : class ENGINE_API engine { HINSTANCE hdll; rendrv* p; void print(HDC h, int x, int y) { p->print(h, x, y); } void init(); void exit(); }; the idea is that rendrv is an abstract base class to two other interfaces, one for drawing in OpenGL and one in DirectX. class GL_API glrendrv : public rendrv { public: virtual void print(HDC h, int x, int y) { char str[] = "glrendrv output"; TextOut(h, x, y, str, strlen(str)); } } now the init function loads explicitly the glrendrv dll and casts it''s rendrv pointer to a glrendrv pointer. now in my launch code, i have the following engine e; e.init(); e.print(HDC, 0, 0); e.exit(); now when e.print is called i get an exception : access violation. can anibody tell me what is wrong, or is it impossible for a class member function in a load time dll, to load dynamicly a class at run time from a dll?
well this could be wrong but in class GL_API

you cant have char str[] initialized to "gl render output"
you have to keep it just char str[]
then initialize to char str[]= "gl render output"
in your constructor
Advertisement
Change the char[] to a char *
Are you sure that the HDC is valid?

"now the init function loads explicitly the glrendrv dll and casts it''s rendrv pointer to a glrendrv pointer."

init() is a void function with no parameters... I am curious as to how you are casting it.

Do init() and exit() actually do anything? do they use the pointer to the rendrv?

Post some more code so we can see exactly what you are doing.
the init function goes like this:

void ENGINE_API engine::init()
{
hdll = LoadLibrary("glrendrv.dll");

GLAPIPROC pfn = (GLAPIPROC)GetProcAddress("CreateGL");

pfn(&p);
}

note the exit function is similar, except it loads the DelGL function.

the CreateGL function, defined in the glrendrv.dll is as follows

void GL_API CreateGL(rendrv** p)
{
*p = new glrendrv;
}

void GL_API DelGL(rendrv**p)
{
delete *p;
}

I also have the typedef
typedef void GL_API (*GLAPIPROC)(rendrv**)

This topic is closed to new replies.

Advertisement