By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 817 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Return Class instance from dynamically loaded DLL?

P: n/a
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
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.