My architecture is as follows:
- Program.exe links to 1.dll
- 1.dll attempts to load DLL files in some directory (i.e. 2.dll) via LoadLibrary
- 1.dll attempts to find a function called "setup" via GetProcAddress("setup")
- 1.dll does some work and may release 2.dll
- The user may want to change the DLLs in the directory, including removing a DLL (without restarting the software)
The issue I'm having is that 2.dll in my example remains locked (error 32), even after FreeLibrary has been called.
In my initial testing Program.exe could LoadLibrary, do something with it and FreeLibrary, which unlocked it, then the same functionality has been transfered into 1.dll, which Program.exe also loaded via LoadLibrary, and the process continued to work perfectly.
In order to avoid dynamically loading 1.dll I linked it with Program.exe, which seems to have broken it, as aside from changing the linking nothing else has changed, and the dlls loaded by 1.dll remain locked until the program is terminated, FreeLibrary still returns true.
As there are a multitude of functions that I would need to dynamically load, which seems rather unrealistic I'd like to fix the issue with other dlls being locked. How can I make the program release unused files, like it did before I linked 1.dll with it?