Return Class instance from dynamically loaded DLL?

P

Peter

I use dynamically loaded dll's a lot in my programs. The one thing i cannot
figure out how do is too to sucessfully pass the address of a class instance
created within the dynamically loaded dll. I step thru the code and confirm
that the class is correctly created in the dll, but as soon as it steps out
of the dll i loose the address. For example:

hLib = LoadLibrary("RasterIO.dll");

ImageIOClass *ImageIO = (ImageIOClass
*)GetProcAddress((HINSTANCE)hLib, "_GetImageIOClass");
if (ImageIO != NULL)
{
TRasterIO *IO;
ImageIO(IO, ...); // instance created with new in dll.
if (IO)
{
// do something with IO
....
}
else
{
return;
}

delete IO;
}
UnloadPackage(hLib);

That is the basic idea of what i am trying to do. If i statically link the
dll i can get an instance of the class no problem. I suppose this is all
something to do with the way dlls handle and share memory - something i
obviously do not understand!

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top