DLL calls with the release of a little body

xiaoxiao2021-03-06  101

Today, I ask questions about DLL loading and release, although I didn't get an answer, I got a good prompt - how to determine that the DLL has been released from memory? Deleting this DLL can be a good way to see if it can be successful.

A lot of trials is made in accordance with this simple and effective way, the process is as follows. Several methods: (1) Static call DLLTEST1.DLL, the handle is stored in the TH variable; (2) Dynamically calls DLLTEST1.DLL, the handle is saved in the TH1 variable; (3) Dynamically call the dlltest2.dll, handle Save TH2 variable;

-----------------------

Conclusion: (1) After the end, the DLL called in the program will be automatically released; (2) If the program is illegally ended or ended, it will also release the called DLL; (3) LoadLibrary a few DLLs, it requires freeelibrary A few times, its essence is Freelibrary once, a reduction of the DLL instance counter, which will release the DLL from memory when zero; (4) There will be different THANDLEs for different DLLs, and Whether he is static loading or dynamically loaded, because each DLL is only loaded to memory once, it has only one handle. If you want to actively release the DLL, you need to record the number of instances.

Question: (1) Is there a way to get the number of instances of the current DLL load? ================================================== Insert A big man's colleague replied. Freelibrary reduces the reference count of the dynamic link library of the current process. When the count is reduced to 0, the dynamic link library module is removed from the address space space of the process, and the dynamic link library module handle is invalid. LoadLibrary This function maps the specified DLL to the address space of the calling process. If the same file has been mapped to the address space of the calling process, the module count is added 1. The function returns the handle returned when the first call loadLibrary is loaded. When the calling process is turned off, the reference count is automatically set, and the DLL module is released. Note that this is just this process module count. During the operation of the program, if you want the dynamic link library module to be released immediately, then call n times to call N times Freelibrary

转载请注明原文地址:https://www.9cbs.com/read-105286.html

New Post(0)