CloseHandle
The CloseHandle function closes an open object handle. This function is used for many different types of objects, including files, processes, threads, security and synchronization objects, and registry keys.
Syntax
BOOL CloseHandle(
HANDLE hObject
);
Parameters
| Parameter | Type | Description |
|---|---|---|
hObject |
HANDLE |
A handle to an open object. This handle must have been created by an appropriate function, such as CreateFile, CreateProcess, or RegOpenKeyEx. |
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 GetLastError.
Remarks
You must close a handle when you are finished with it. Failure to do so can lead to resource leaks.
For file handles, using CloseHandle is equivalent to calling CloseHandle(hFile) where hFile is the handle returned by CreateFile.
The handle hObject must be a valid handle to an object that has been opened or created by the current process. It is an error to close a handle that has already been closed or that was opened by another process.
Requirements
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | windows.h |
| Library | Kernel32.lib |
| DLL | Kernel32.dll |