UnlockFile

  BOOL UnlockFile(hFile, dwFileOffsetLow, dwFileOffsetHigh, cbUnlockLow, cbUnlockHigh)    
  HANDLE hFile; /* handle of file to unlock */
  DWORD dwFileOffsetLow; /* low 32 bits of lock region offset */
  DWORD dwFileOffsetHigh; /* high 32 bits of lock region offset */
  DWORD cbUnlockLow; /* low 32 bits of length to unlock */
  DWORD cbUnlockHigh; /* high 32 bits of length to unlock */

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

Parameters

hFile

Identifies 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

Specifies the low 32 bits of the starting byte offset in the file where the locked region begins.

dwFileOffsetHigh

Specifies the high 32 bits of the starting byte offset in the file where the locked region begins.

cbUnlockLow

Specifies the low 32 bits of the length of the byte range to be unlocked.

cbUnlockHigh

Specifies the high 32 bits of the length of the byte range to be unlocked.

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.

Comments

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

A process should not terminate with a portion of a file locked or close a file that has locked regions.

For MS-DOS-based systems running SHARE.EXE, the lock semantics work as described above. Without SHARE.EXE, all attempts to lock or unlock a file will fail.

See Also

LockFile, CreateFile