FFLock64 Function |
Namespace: XSharp.Core
Tip |
---|
The low level File IO functions in the X# runtime are using .Net filestreams in the background. That means that the file handles returned by FOpen() and FCreate() are not 'normal' file handles, but unique identifiers that are used to find the underlying stream object in a collection of streams in the runtime. That also means that you can't use file handles for functions such as FRead() and FWrite() that were not created in the X# runtime. If you want to access the underlying FileStream, then you should call the function FGetStream(IntPtr) |
1ptrHandle := FOpen2("c:\data\myfile.txt", ; 2 FO_READWRITE + FO_SHARED) 3IF FFLock(ptrHandle, 300, 100) 4 ? "Locked OK" 5ENDIF
1FUNCTION FileLock(ptrHandle AS PTR,; 2 dwOffset AS DWORD, dwLength AS DWORD,; 3 wSeconds AS DWORD) AS LOGIC PASCAL 4 LOCAL lForever AS LOGIC 5 IF FFLock(ptrHandle, dwOffset, dwLength) 6 RETURN TRUE // Locked 7 ENDIF 8 // If wSeconds is zero, retry until successful 9 lForever := (wSeconds = 0) 10 DO WHILE (lForever .OR. wSeconds > 0) 11 IF FFLock(ptrHandle, dwOffset, dwLength) 12 RETURN TRUE // Locked 13 ENDIF 14 InKey(.5) // Wait up 15 nSeconds -= 1 16 ENDDO 17 RETURN FALSE // Not locked