This topic has not yet been rated - Rate this topic

CFile::LockRange

Locks a range of bytes in an open file, throwing an exception if the file is already locked.

virtual void LockRange( 
   ULONGLONG dwPos, 
   ULONGLONG dwCount  
);
dwPos

The byte offset of the start of the byte range to lock.

dwCount

The number of bytes in the range to lock.

Locking bytes in a file prevents access to those bytes by other processes. You can lock more than one region of a file, but no overlapping regions are allowed.

When you unlock the region, using the UnlockRange member function, the byte range must correspond exactly to the region that was previously locked. The LockRange function does not merge adjacent regions; if two locked regions are adjacent, you must unlock each region separately.

NoteNote:

This function is not available for the CMemFile-derived class.

CFile cfile;
cfile.Open(_T("LockRange_File.dat"), CFile::modeCreate |
   CFile::modeReadWrite);
ULONGLONG dwPos = 10;
ULONGLONG dwCount = 100;
cfile.LockRange(dwPos, dwCount);

// do something with the file

cfile.UnlockRange(dwPos, dwCount);

Header: afx.h

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.