FUNCTION FFLock( ptrHandle AS IntPtr, offset AS DWORD, length AS DWORD ) AS LOGIC
public static bool FFLock( IntPtr ptrHandle, uint offset, uint length )
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()
ptrHandle := FOpen2("c:\data\myfile.txt", ; FO_READWRITE + FO_SHARED) IF FFLock(ptrHandle, 300, 100) ? "Locked OK" ENDIF
FUNCTION FileLock(ptrHandle AS PTR,; dwOffset AS DWORD, dwLength AS DWORD,; wSeconds AS DWORD) AS LOGIC PASCAL LOCAL lForever AS LOGIC IF FFLock(ptrHandle, dwOffset, dwLength) RETURN TRUE // Locked ENDIF // If wSeconds is zero, retry until successful lForever := (wSeconds = 0) DO WHILE (lForever .OR. wSeconds > 0) IF FFLock(ptrHandle, dwOffset, dwLength) RETURN TRUE // Locked ENDIF InKey(.5) // Wait up nSeconds -= 1 ENDDO RETURN FALSE // Not locked