Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 1.97 KB

LockFile.md

File metadata and controls

67 lines (47 loc) · 1.97 KB

Home

Function name : LockFile

Group: File Management - Library: kernel32


Locks a region in an open file. Locking a region prevents other processes from accessing the region.


Code examples:

Locking and unlocking file of a VFP table

Declaration:

BOOL LockFile(
  HANDLE hFile,                   // handle to file
  DWORD dwFileOffsetLow,          // low-order word of offset
  DWORD dwFileOffsetHigh,         // high-order word of offset
  DWORD nNumberOfBytesToLockLow,  // low-order word of length
  DWORD nNumberOfBytesToLockHigh  // high-order word of length
);  

FoxPro declaration:

DECLARE INTEGER LockFile IN kernel32;
	INTEGER hFile,;
	INTEGER dwFileOffsetLow,;
	INTEGER dwFileOffsetHigh,;
	INTEGER nNumberOfBytesToLockLow,;
	INTEGER nNumberOfBytesToLockHigh  

Parameters:

hFile [in] Handle to the file with a region to be locked. The file handle must have been created with GENERIC_READ or GENERIC_WRITE access to the file (or both).

dwFileOffsetLow [in] Specifies the low-order word of the starting byte offset in the file where the lock should begin.

dwFileOffsetHigh [in] Specifies the high-order word of the starting byte offset in the file where the lock should begin.

nNumberOfBytesToLockLow [in] Specifies the low-order word of the length of the byte range to be locked.

nNumberOfBytesToLockHigh [in] Specifies the high-order word of the length of the byte range to be locked.


Return value:

If the function succeeds, the return value is nonzero.


Comments:

MSDN: If LockFile cannot lock a region of a file, it returns zero immediately. It does not block. To issue a file lock request that will block until the lock is acquired, use LockFileEx without LOCKFILE_FAIL_IMMEDIATELY.