UnlockFile Function

The UnlockFile function releases a previously locked region of a file.

Syntax

BOOL UnlockFile(
  HANDLE hFile,
  DWORD dwFileOffsetLow,
  DWORD dwFileOffsetHigh,
  DWORD nNumberOfBytesToUnlockLow,
  DWORD nNumberOfBytesToUnlockHigh
);

Parameters

Parameter Description
hFile A handle to the file that contains the locked region. This handle must have been created by a call to the CreateFile function.
dwFileOffsetLow The low-order 32 bits of the starting byte offset of the region to unlock.
dwFileOffsetHigh The high-order 32 bits of the starting byte offset of the region to unlock.
nNumberOfBytesToUnlockLow The low-order 32 bits of the number of bytes to unlock.
nNumberOfBytesToUnlockHigh The high-order 32 bits of the number of bytes to unlock.

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

The UnlockFile function releases byte-range locks previously placed on a file by the LockFile function. The parameters specify the file handle, the starting offset of the locked region, and the number of bytes in the locked region.

It is important that the parameters passed to UnlockFile exactly match those used in the corresponding LockFile call. If there is a mismatch, the behavior is undefined.

This function is typically used in scenarios where multiple processes might need to access different parts of the same file concurrently. By using LockFile and UnlockFile, applications can ensure data integrity by preventing simultaneous modification of critical file sections.

Important Considerations:

Requirements

Attribute Value
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header fileapi.h
Library Kernel32.lib
DLL Kernel32.dll

See Also

LockFile

CreateFile

File Management Functions