如果加载它的 DLL 被卸载,一个 DLL 会被删除吗? [英] Does a DLL get removed if the DLL that loaded it is unloaded?

查看:31
本文介绍了如果加载它的 DLL 被卸载,一个 DLL 会被删除吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

采用标准的 Windows 应用程序.它使用 LoadLibrary 加载一个 DLL 以调用其中的函数(我们将称之为 DLL_A).该函数加载另一个 DLL(我们将其称为 DLL_B).应用程序现在使用 FreeLibrary 卸载 DLL_A DLL,因为它不再需要它.

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.

问题是:DLL_B 是否仍在内存中并已加载?

这是我可以依赖的东西,还是没有记录?

Is this something I can depend upon, or is it undocumented?

推荐答案

没有.DLL_B 不会被卸载.DLL_A 进行的 LoadLibrary() 调用将增加 DLL_B 的加载计数.由于DLL_B 没有相应的FreeLibrary() 调用,因此引用计数不会为零.

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.

来自 LoadLibrary() 文档:

From the LoadLibrary() docs:

系统维护一个每个进程所有加载模块的引用计数.调用 LoadLibrary 会增加引用计数.调用免费图书馆或FreeLibraryAndExitThread 函数减少引用计数.这系统卸载模块时引用计数达到零或当进程终止(无论引用计数).

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).

这篇关于如果加载它的 DLL 被卸载,一个 DLL 会被删除吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆