Platform SDK: Files and I/O

UnlockFile

The UnlockFile function unlocks a region in an open file. Unlocking a region enables other processes to access the region.

For an alternate way to specify the region, use the UnlockFileEx function.

BOOL UnlockFile(
  HANDLE hFile,                    // handle to file
  DWORD dwFileOffsetLow,           // low-order word of start
  DWORD dwFileOffsetHigh,          // high-order word of start
  DWORD nNumberOfBytesToUnlockLow, // low-order word of length
  DWORD nNumberOfBytesToUnlockHigh // high-order word of length
);

Parameters

hFile
[in] Handle to a file that contains a region locked with LockFile. The file handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.
dwFileOffsetLow
[in] Specifies the low-order word of the starting byte offset in the file where the locked region begins.
dwFileOffsetHigh
[in] Specifies the high-order word of the starting byte offset in the file where the locked region begins.

Windows 95/98: dwFileOffsetHigh must be 0, the sign extension of the value of dwFileOffsetLow. Any other value will be rejected.

nNumberOfBytesToUnlockLow
[in] Specifies the low-order word of the length of the byte range to be unlocked.
nNumberOfBytesToUnlockHigh
[in] Specifies the high-order word of the length of the byte range to be unlocked.

Return Values

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

Unlocking a region of a file releases a previously acquired lock on the file. The region to unlock must correspond exactly to an existing locked region. Two adjacent regions of a file cannot be locked separately and then unlocked using a single region that spans both locked regions.

If a process terminates with a portion of a file locked or closes a file that has outstanding locks, the behavior is not specified.

This function works on a file allocation table (FAT) – based file system only if the operating system is running SHARE.EXE.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.

See Also

File I/O Overview, File I/O Functions, CreateFile, LockFile, UnlockFileEx