Handles API Reference
This section provides documentation for the Windows Kernel Handles API, which allows developers to interact with and manage various system objects through their unique identifiers, known as handles.
What are Handles?
A handle is a system-defined value that identifies a system resource. The operating system uses handles to manage access to objects such as files, processes, threads, windows, and memory blocks. When an application requests access to a system resource, the system creates an entry in a handle table and returns a handle to the application. The application then uses this handle to refer to the resource in subsequent operations.
Handle Management Functions
CloseHandle
HANDLE hObject
);
Closes an open object handle. This function decrements the handle count of the specified object and, if the count becomes zero, deletes the object’s entry from the system's object table.
GetCurrentProcess
Returns a pseudo handle for the current process. A pseudo handle is a special constant that, like a pointer, distinguishes between the current process and any other process, including the system.
GetCurrentThread
Returns a pseudo handle for the current thread. A pseudo handle is a special constant that, like a pointer, distinguishes between the current thread and any other thread.
DuplicateHandle
HANDLE hSourceProcessHandle,
HANDLE hSourceHandle,
HANDLE hTargetProcessHandle,
LPHANDLE lpTargetHandle,
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwOptions
);
Duplicates an existing handle in the system. This enables a process to have access to the same object that another process has access to.
Key Concepts
- Handle Table: A data structure maintained by the kernel for each process, mapping handles to object pointers.
- Object Manager: The kernel component responsible for creating, managing, and protecting system objects.
- Access Mask: A bitmask that specifies the desired access rights to an object.
- Inheritance: The ability for a child process to inherit handles from its parent process.