次の方法で共有


UnlockFileEx (Compact 2013)

3/26/2014

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

Syntax

BOOL UnlockFileEx(
  HANDLE hFile, 
  DWORD dwReserved,
  DWORD nNumberOfBytesToLockLow,
  DWORD nNumberOfBytesToLockHigh,
  LPOVERLAPPED lpOverlapped
);

Parameters

  • hFile
    [in] Handle to a file that contains a region locked by the LockFileEx function. The file handle must have been created with the GENERIC_READ or GENERIC_WRITE access right.
  • dwReserved
    Reserved. Set to zero.
  • nNumberOfBytesToLockLow
    [in] Low-order portion of the length of the byte range to unlock.
  • nNumberOfBytesToLockHigh
    [in] High-order portion of the length of the byte range to unlock.
  • lpOverlapped
    [in] Pointer to an OVERLAPPED structure that is used with the unlock request. This structure contains the file offset of the beginning of the unlock range.

Return Value

Nonzero indicates success. Zero indicates failure. For 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 locks are unlocked by the OS. However, the time it takes for the OS to unlock these locks depends upon available system resources. Therefore, explicitly unlock all locked files when a process ends. Otherwise, access to these files can be denied if the OS has not yet unlocked them.

Requirements

Header

winbase.h

Library

coredll.lib

See Also

Reference

File I/O Functions
LockFileEx
OVERLAPPED