RTR3DECL(int)  RTFileLock(RTFILE hFile, unsigned fLock, int64_t offLock, uint64_t cbLock)
{
    Assert(offLock >= 0);

    /* Check arguments. */
    if (fLock & ~RTFILE_LOCK_MASK)
    {
        AssertMsgFailed(("Invalid fLock=%08X\n", fLock));
        return VERR_INVALID_PARAMETER;
    }

    /* Prepare flags. */
    Assert(RTFILE_LOCK_WRITE);
    DWORD dwFlags = (fLock & RTFILE_LOCK_WRITE) ? LOCKFILE_EXCLUSIVE_LOCK : 0;
    Assert(RTFILE_LOCK_WAIT);
    if (!(fLock & RTFILE_LOCK_WAIT))
        dwFlags |= LOCKFILE_FAIL_IMMEDIATELY;

    /* Windows structure. */
    OVERLAPPED Overlapped;
    memset(&Overlapped, 0, sizeof(Overlapped));
    Overlapped.Offset = LOW_DWORD(offLock);
    Overlapped.OffsetHigh = HIGH_DWORD(offLock);

    /* Note: according to Microsoft, LockFileEx API call is available starting from NT 3.5 */
    if (LockFileEx((HANDLE)RTFileToNative(hFile), dwFlags, 0, LOW_DWORD(cbLock), HIGH_DWORD(cbLock), &Overlapped))
        return VINF_SUCCESS;

    return RTErrConvertFromWin32(GetLastError());
}
RTR3DECL(int)  RTFileUnlock(RTFILE hFile, int64_t offLock, uint64_t cbLock)
{
    Assert(offLock >= 0);

    if (UnlockFile((HANDLE)RTFileToNative(hFile),
                   LOW_DWORD(offLock), HIGH_DWORD(offLock),
                   LOW_DWORD(cbLock), HIGH_DWORD(cbLock)))
        return VINF_SUCCESS;

    return RTErrConvertFromWin32(GetLastError());
}
//---------------------------------------------------------------------------
//  Set the file position pointer
//
__int64 TImageStore::Seek(__int64 Offset, DWORD MoveMethod)
{
    __int64 NewPosition;
#ifdef _WIN32
#if 0
    if (FType == isNBD) {

        switch (MoveMethod) {
        case FILE_BEGIN:
            FPosition = Offset;
            break;
        case FILE_CURRENT:
            FPosition += Offset;
            break;
        case FILE_END:
            FPosition = FGeometry.Bytes + Offset;
            break;
        }  // switch (MoveMethod)
    } else {
#endif

        DWORD nError;
        LOW_DWORD(Offset) = SetFilePointer(hHandle, LOW_DWORD(Offset), &HIGH_DWORD(Offset), MoveMethod);
        if (LOW_DWORD(Offset) == INVALID_SET_FILE_POINTER && (nError = GetLastError()) != NO_ERROR) {
            printf ("Seek error with \n");
            //throw ESelfImageFileError("Seek error with " + FFileName + ": '" + GetErrorMessage(nError) + "'");
        } else
            FPosition = Offset;
#else
    NewPosition = lseek (hHandle,Offset, MoveMethod);
    if (NewPosition<0) {
        // ERROR
        printf ("Seek error with \n");
    } else
        FPosition = NewPosition;
#endif
#if 0
    }  // else if (FType != NBD)
#endif

    return FPosition;
}  // bool __fastcall TImageStore::Seek(__int64)