UnlockFileEx
The UnlockFileEx function releases a lock on a specified range of bytes in a file.
BOOL UnlockFileEx(
HANDLE hFile,
DWORD dwReserved,
DWORD nNumberOfBytesToUnlock,
DWORD nNumberOfBytesToUnlockHigh,
OVERLAPPED *lpOverlapped
);
HANDLE hFile,
DWORD dwReserved,
DWORD nNumberOfBytesToUnlock,
DWORD nNumberOfBytesToUnlockHigh,
OVERLAPPED *lpOverlapped
);
Parameters
| Parameter | Description |
|---|---|
hFile |
A handle to the file that contains the locked byte range. This handle must have been created by the CreateFile function with the FILE_SHARE_WRITE access right. |
dwReserved |
This parameter is reserved and must be zero. |
nNumberOfBytesToUnlock |
The lower 32 bits of the number of bytes to unlock. |
nNumberOfBytesToUnlockHigh |
The higher 32 bits of the number of bytes to unlock. |
lpOverlapped |
A pointer to an OVERLAPPED structure that contains the offset within the file where the lock begins. The structure must contain the offset members (Offset and OffsetHigh) that were used to specify the lock. |
Return Value
| Value | Meaning |
|---|---|
TRUE |
The function was successful. |
FALSE |
The function failed. To get extended error information, call GetLastError. |
Remarks
The UnlockFileEx function is the counterpart to the LockFileEx function. To unlock a byte range, you must specify the same file handle and offset as when the lock was acquired. The number of bytes to unlock should match the size of the locked region.
If the lpOverlapped parameter is NULL, the lock must be at the current file pointer position and the number of bytes to unlock must be zero. This is typically used to unlock the entire region from the current file position to the end of the file.
It is crucial to unlock byte ranges correctly to avoid potential deadlocks or data corruption. Ensure that all locks are released when they are no longer needed.
Note: The
dwReserved parameter is not used and must be set to zero.
Important: If
lpOverlapped is not NULL, the Offset and OffsetHigh members of the OVERLAPPED structure must specify the byte offset of the locked region.