Is it possible to connect a dll in memory to prevent unloading?

Is there any way on Windows to prevent our DLL from unloading through FreeLibrary? That is, "fix" it in memory for the life of the process?

+3
source share
3 answers

Yes. Call LoadLibrary () in this DLL. This will increase the internal reference count. FreeLibrary () only unloads the DLL when its internal reference count drops to zero. If you are LoadLibrary and never FreeLibrary, the DLL will be stuck in memory for the whole life of your process.

, - FreeLibrary() DLL , , , , - , DLL . , , LoadLibrary.

+6

, , "" :

GetModuleHandleEx GET_MODULE_HANDLE_EX_FLAG_PIN.

MSDN:

, , , FreeLibrary.

- ...

+17

MSVC has options (at least in VC 2005+) for "Delay loading DLL" and support for "Delay Loaded DLL Unload". You might also want to look at these settings, ensuring that Unload is not supported.

0
source

Source: https://habr.com/ru/post/1759036/