We're developing a cross platform application and one of the platforms is

We have a Class say

A that instantiates a Library Class say Libr which then loads a DLL and
stores the HINSTANCE of the loaded DLL.

The instance of Class A is then stored in a Map.

As required another instance of class A is created for another DLL and that
instantiates another library class (platform specific - the pointer is to
Library which could be WinLibrary or LinuxLibrary subclasses) and that is
stored in the STL Map as well.

When the first instance is referenced, and I try to use the function
pointers I got, I find that HINSTANCE still has a valid pointer, but seems
to be out of scope and the FP crashes the code. HINSTNACE seems to have a
member called "unused" that for some reason gets reset to 0 at this point.
Calling LoadLibrary again seems to be the only way to fix this. But since
this requires other reinitialization and allocation, this will cause a
memory leak and does not seem to be the way to fix this.

When I just load the Dll "unused" has a negative value. This worked fine as
long as HINSTANCE was a member of Class A itself - so I don't know if this
is because of the additional indirection and the STL map not supporting a
deep enough copy. Free Library is not called along the way.

If anyone knows what "unused" is and why it would set to 0, I would
appreciate the same.