网站首页  词典首页

请输入您要查询的函数:

 

术语 freelibrary
释义 FreeLibrary
语法:
C++
BOOL WINAPI FreeLibrary(
__in HMODULE hModule
);
FreeLibrary函数
释放加载的动态链接库(DLL)模块,如有必要,它的引用计数递减。当引用计数为零时,该模块卸载从调用进程的地址空间和处理不再有效。
参数
hModule [in]
一个句柄,装载库模块。的LoadLibrary,LoadLibraryEx,GetModuleHandle,或GetModuleHandleEx函数返回此句柄。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError函数。
备注
该系统维护每个加载的模块的每个进程的引用计数。一个是在进程初始化由于加载时动态链接加载模块的一个引用计数。对于一个模块引用计数递增每次模块是由调用LoadLibrary加载。引用计数也递增到LoadLibraryEx调用,除非正在加载模块为首次被作为数据或图像文件加载。
引用计数递减每次FreeLibrary或FreeLibraryAndExitThread功能的模块调用。当一个模块的引用计数为零或进程终止,系统卸载从进程的地址空间模块。库前卸载模块,系统可提供的模块分离的过程中通过调用模块的DllMain函数,如果它已与DLL_PROCESS_DETACH的价值之一。这样做使库模块有机会清理目前的进程所作的分配资源。经过入口点函数返回时,库模块删除从当前进程的地址空间。
这是不安全的DllMain中调用FreeLibrary。有关详细信息,请参阅在DllMain备注部分。
调用FreeLibrary不影响正在使用相同的模块的其他进程。
使用时要小心调用与处理GetModuleHandle返回FreeLibrary。该GetModuleHandle函数不增加一个模块的引用计数,因此,通过本句柄FreeLibrary可能导致模块被卸载过早。
一个线程必须卸载DLL文件,其中正在执行,然后终止本身应该呼吁FreeLibraryAndExitThread而不是调用FreeLibrary和ExitThread分开。否则,竞争状态可能会发生。有关详细信息,请参阅FreeLibraryAndExitThread备注部分。
实例
有关示例,请参阅使用运行时动态链接。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
的DllMain
动态链接库函数
FreeLibraryAndExitThread
GetModuleHandle
GetModuleHandleEx
调用LoadLibrary
运行时动态链接
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==FreeLibrary Function
Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count. When the reference count reaches zero, the module is unloaded from the address space of the calling process and the handle is no longer valid.
Syntax
C++
BOOL WINAPI FreeLibrary(
__in HMODULE hModule
);
Parameters
hModule [in]
A handle to the loaded library module. The LoadLibrary , LoadLibraryEx , GetModuleHandle , or GetModuleHandleEx function returns this handle.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call the GetLastError function.
Remarks
The system maintains a per-process reference count for each loaded module. A module that was loaded at process initialization due to load-time dynamic linking has a reference count of one. The reference count for a module is incremented each time the module is loaded by a call to LoadLibrary . The reference count is also incremented by a call to LoadLibraryEx unless the module is being loaded for the first time and is being loaded as a data or image file.
The reference count is decremented each time the FreeLibrary or FreeLibraryAndExitThread function is called for the module. When a module's reference count reaches zero or the process terminates, the system unloads the module from the address space of the process. Before unloading a library module, the system enables the module to detach from the process by calling the module's DllMain function, if it has one, with the DLL_PROCESS_DETACH value. Doing so gives the library module an opportunity to clean up resources allocated on behalf of the current process. After the entry-point function returns, the library module is removed from the address space of the current process.
It is not safe to call FreeLibrary from DllMain. For more information, see the Remarks section in DllMain .
Calling FreeLibrary does not affect other processes that are using the same module.
Use caution when calling FreeLibrary with a handle returned by GetModuleHandle. The GetModuleHandle function does not increment a module's reference count, so passing this handle to FreeLibrary can cause a module to be unloaded prematurely.
A thread that must unload the DLL in which it is executing and then terminate itself should call FreeLibraryAndExitThread instead of calling FreeLibrary and ExitThread separately. Otherwise, a race condition can occur. For details, see the Remarks section of FreeLibraryAndExitThread .
Examples
For an example, see Using Run-Time Dynamic Linking .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
DllMain
Dynamic-Link Library Functions
FreeLibraryAndExitThread
GetModuleHandle
GetModuleHandleEx
LoadLibrary
Run-Time Dynamic Linking
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms683152(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:31:59