I have to load a 3rd party DLL in my project, so I use
HMODULE m_Instance;
...
m_Instance = LoadLibrary("ThirdParty.dll");
My project is yet another DLL that is called by the master application.
At some point the application destroys my DLL then recreates it.
In which time my program calls
FreeLibrary
to unload the ThirdParty.dll before dying.
The application recreates my DLL so somewhere in the start up sequence, I call
LoadLibrary
again.
The call gets stuck here and doesn't return.
As an observation, here are some things I noticed that may have something to do with the problem:
When ThirdParty.dll is loaded, a whole bunch of other DLLs are loaded by ThirdParty.dll.
When ThirdParty.dll is unloaded, I can see it being unloaded in the output window if I'm debugging. However, the rest of the DLLs that ThirdParty.dll seemed to have loaded are not listed as being unloaded.
Then, on restart (my DLL has been released and recreated, but the main application has remained), ThirdParty.dll is loaded and that's where it gets stuck.
I'm wondering if the DLLs loaded by ThirdParty.dll are not released appropriately when I call
FreeLibrary
.
However, that's just my guess, and I rather hope that's not the case because I can't fix what' in ThirdParty.dll.
Is there anything I can do to make sure I can load ThirdParty.dll a second time?