Author Topic: Are there differences between LockFile and CreateFile?  (Read 345 times)

morgot

  • Regular Member
  • *
  • Posts: 46
Are there differences between LockFile and CreateFile?
« on: June 13, 2019, 02:08:01 AM »
Hello,
if I open file with CreateFile,"filename",..,0 (NO FILE_SHARE option) nobody can't open file or delete it.

If I use function LockFile for all file size (all offsets), is there is same result? What differences?

I need to work with file, that nobody read/writes to it, because file may be corrupt. What solution is better to use?
Sorry for the bad English

Tedd

  • Member
  • ***
  • Posts: 377
  • Procrastinor Extraordinaire
Re: Are there differences between LockFile and CreateFile?
« Reply #1 on: June 13, 2019, 05:21:04 AM »
If you open a file with no sharing then nobody else can open the file, whereas with a lock you can limit access to specific parts of the file while still allowing access to other parts of the same file.

In your case, locking the entire file would have the same result.

If you're going to be opening the file anyway, obviously you'll open it with no sharing, so then the extra lock is unnecessary.
Potato2