[python-win32] Re: Help: using msvcrt for file locking

Mark Hammond MarkH@ActiveState.com
Mon, 27 Aug 2001 12:11:10 +1000


> :A quick look at portalocker implies you will also want to drop all
> :references to "_overlapped" - replace them with "None".
>
> I tried that. Unfortunately, "None" didn't work. It gave me an error
> message asking for an integer.

Hrm - that is strange.  A quick check over the C++ extension code certainly
implies it should work.

> win32file.LockFile(fd, win32con.LOCKFILE_EXCLUSIVE_LOCK, 0, 0xffff0000,0)

The LockFile documentation states that the first integer "Specifies the
low-order word of the starting byte offset in the file where the lock should
begin." - ie, it is *not* the flag that LockFileEx supports.  Set this to
zero.

The documentation for UnlockFile states that the unlocked region must be
_exactly_ as specified in the LockFile call - hence your error when
unlocking - the start offset is not identical.

>Would getting the Programming Python on Win32 help me learn this Windows
>API stuff. Or would I have to get a separate book on Windows API and then
>get the Programming Python on Win32 to help me translate that knowledge
into Python?

It would not help with this specific corner of the API - file locking is not
covered.  In general, your best approach is to find documentation or
examples in any language, and then use PPW32 to help translate to Python
code.

I would suggest buying a copy of the MSDN "library" on CD - I don't think it
is too expensive, and is a very useful resource, including lots of sample
code.  I have not purchased a Win32 API book in over 5 years (and even the
one I got then was pretty useles :)

Mark.