Return Class instance from dynamically loaded DLL?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter

    Return Class instance from dynamically loaded DLL?

    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("Ra sterIO.dll");

    ImageIOClass *ImageIO = (ImageIOClass
    *)GetProcAddres s((HINSTANCE)hL ib, "_GetImageIOCla ss");
    if (ImageIO != NULL)
    {
    TRasterIO *IO;
    ImageIO(IO, ...); // instance created with new in dll.
    if (IO)
    {
    // do something with IO
    ....
    }
    else
    {
    return;
    }

    delete IO;
    }
    UnloadPackage(h Lib);

    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


Working...