FreeLibrary 和 AfxFreeLibrary

来源:互联网 发布:用u盘安装linux 编辑:程序博客网 时间:2024/06/06 13:20

首先是MSDN ONLINE上的一段解释:

FreeLibrary 和 AfxFreeLibrary

 

不再需要 DLL 模块时,显式链接到 DLL 的进程调用 FreeLibrary 函数。此函数递减模块的引用数,如果引用数为零,此函数便从进程的地址空间中取消模块的映射。

MFC 应用程序应使用 AfxFreeLibrary 而非 FreeLibrary 卸载扩展 DLL。AfxFreeLibrary 的接口(函数原型)与 FreeLibrary 相同。

 

MSDN 里的一段注释:

Be sure to use AfxFreeLibrary and AfxLoadLibrary (instead of the Win32 functions FreeLibrary and LoadLibrary) if your application uses multiple threads. Using AfxLoadLibrary and AfxFreeLibrary ensures that the startup and shutdown code that executes when the extension DLL is loaded and unloaded does not corrupt the global MFC state.

从后面的注释可以看到,AfxFreeLibraray/AfxLoadLibrary加入了对MFC框架的保护。针对MFC扩展 DLL,用他们取代Win32 API是个更保险的办法。