FreeLibrary 百科内容来自于: 百度百科

VB

VB声明

Declare Function FreeLibrary Lib "kernel32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long

说明

释放指定的动态链接库,它们早先是用LoadLibrary API函数装载的

返回值

Long,非零表示成功,零表示失败。会设置GetLastError

参数表

参数 类型及说明

hLibModule Long,要释放的一个库句柄

在VB里使用

只能用这个函数释放那些由应用程序明确装载的DLL。对LoadLibrary的每一次调用都应该有一个对应的FreeLibrary调用

delphi声明

function FreeLibrary; external kernel32 name 'FreeLibrary';

C++

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. TheLoadLibrary,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 theGetLastErrorfunction.

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 toLoadLibrary. The reference count is also incremented by a call toLoadLibraryExunless 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'sDllMainfunction, 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 fromDllMain. For more information, see the Remarks section inDllMain.
Calling FreeLibrary does not affect other processes that are using the same module.
Use caution when calling FreeLibrary with a handle returned byGetModuleHandle. 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.
Windows Phone 8: This API is supported.

Examples

For an example, see Using Run-Time Dynamic Linking.

Requirements

Minimum supported client
Windows XP [desktop apps | Windows Store apps]
Minimum supported server
Windows Server 2003 [desktop apps | Windows Store apps]
Header
Winbase.h (include Windows.h)
Library
Kernel32.lib
DLL
Kernel32.dll

See also

DllMainDynamic-Link Library Functions FreeLibraryAndExitThreadGetModuleHandleGetModuleHandleExLoadLibraryRun-Time Dynamic Linking
$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定