- When does Windows Operating System load a DLL into memory?
- Does the operation occur when the application starts or when the application first calls one of the procedures in the DLL?
- Could a DLL be unloaded once it has been loaded?
When does Windows Operating System load a DLL into memory? Does the operation occur
Share
If you’ve linked your EXE to a DLL implicitly through a .lib file, like you normally do for most windows apis such as user32.dll and kernel32.dll, then the defautl behavior is for the DLL to get loaded when the process starts and before your WinMain/main function is called. See below for delay loading…
If one DLL depends on another, it will load its dependencies first if they are not already loaded.
If you are explicitly loading code through a DLL (LoadLibrary, CoCreateInstance, etc…), then it will get loaded upon making these calls
You can have it both ways. By default, DLL is loaded at app startup. If you used the /DELAYLOAD linker flag, the DLL may be able to defer being loaded until its actually needed. This is “best effort” – if there are weird export dependencies with global variables, it may not work.
Short answer is “no” for implicit DLL dependencies that you’ve linked. FreeLibrary and CoFreeUnusedLibrary can be used for LoadLibrary/CoCreateInstance calls.