Zitat: |
The LockFile function locks the specified file for exclusive access by the calling process using the specified file handle. |
You may lock a specific region of the file only. The mechanism is more or less implemented by OS and FS-driver. To know more about it, try to disassemble or buy the source from MS.
On NT the implementation is AFAIK comparable to *nix implementations. But on 9x/Me there are some flaws - you can note this by studying the Apache source and documentation.
LockFileEx() just lets you specify flags (immediate fail, exclusive vs. shared lock) ... furthermore if fail immediately is not set you may specify an overlap routine that is called if the lock was obtained ... this shows another detail of the LockFile(Ex) routines. It's only possible to lock files exclusively if they are not referenced so far ... else the lock is obtained ASAP.
Locking means prevention of write access to the file - meaning that succeeding access by other process will fail until the file is unlocked.
(Web servers make heavy use of this, e.g. for the log files)