Take a standard Windows application. It loads a DLL using LoadLibrary to call a function in it (we'll call this DLL_A). That function loads another DLL (we'll call it DLL_B). The application now unloads the DLL_A DLL using FreeLibrary as it no longer requires it.
The question is: Is DLL_B still in memory and loaded?
Is this something I can depend upon, or is it undocumented?
If your asking if you can safely unload/unmap a DLL loaded in a process from code in the DLL itself, the answer is no - there isn't really a safe way to do this. Think about it this way: Unloading a DLL is done by decrementing it's reference count using FreeLibrary().
Unzip it and run the executable (procexp.exe) on the target machine as an administrator. Once running, enable viewing of loaded DLLs by either pressing CTRL+D or using the View > Lower Pane View > DLLs entry from the menu bar. Select the target process in the upper pane. The lower pane should now show loaded modules.
There is no way to unload DLL . Once you load the DLL into AutoCAD, it will be locked then by AutoCAD. You have to close AutoCAD to build that again.
DLL files may be explicitly loaded at run-time, a process referred to simply as run-time dynamic linking by Microsoft, by using the LoadLibrary (or LoadLibraryEx ) API function. The GetProcAddress API function is used to look up exported symbols by name, and FreeLibrary – to unload the DLL.
No. DLL_B
will not be unloaded. The LoadLibrary()
call made by DLL_A
will increment the load count for DLL_B
. Since there is no corresponding FreeLibrary()
call for DLL_B
, the refcount will not go to zero.
From the LoadLibrary() docs:
The system maintains a per-process reference count on all loaded modules. Calling LoadLibrary increments the reference count. Calling the FreeLibrary or FreeLibraryAndExitThread function decrements the reference count. The system unloads a module when its reference count reaches zero or when the process terminates (regardless of the reference count).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With