[API]
SetFilePointer
ReadFile
WriteFile

[DEFINE]
Public Const BinaryMoveFileData_DefaultBlockSize As Long = &H3FFF00
'Public BinaryMoveFileData_AbortCopying As Boolean

[CODE]
'Public Function BinaryMoveFileDataEx(ByVal SourceFile As Long, ByVal Size As Long, ByVal StartPos As Long, ByVal NewPos As Long, Optional ByVal DestinationFile As Long = -1&, Optional ByVal BlockSize As Long = BinaryMoveFileData_DefaultBlockSize, Optional ByVal ProgressControl As Long, Optional ByVal ProgressStart As Long = 0&, Optional ByVal ProgressTotal As Long = 0&, Optional ByVal ProgressWidth As Long = -1&) As Boolean
Public Function BinaryMoveFileDataEx(ByVal SourceFile As Long, ByVal Size As Long, ByVal StartPos As Long, ByVal NewPos As Long, Optional ByVal DestinationFile As Long = -1&, Optional ByVal BlockSize As Long = BinaryMoveFileData_DefaultBlockSize, Optional ByVal ProgressControl As Long, Optional ByVal ProgressStart As Double = 0#, Optional ByVal ProgressTotal As Double = 0#, Optional ByVal ProgressWidth As Double = -1#) As Boolean
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
  Dim xChar1 As String

  If Not Size = 0& Then
    If DestinationFile = -1& Then DestinationFile = SourceFile
    If Not (DestinationFile = SourceFile And StartPos = NewPos) Then
      If ProgressWidth = -1 Then ProgressWidth = Size
      'BinaryMoveFileData_AbortCopying = False

      If BlockSize > Size Then BlockSize = Size
      xChar1 = String(BlockSize, vbNullChar)
      xLong2 = Size
      BinaryMoveFileDataEx = True
      Do
        If xLong2 > BlockSize Then
          xLong1 = BlockSize
          xLong2 = xLong2 - xLong1
          Else
          xLong1 = xLong2
          xLong2 = 0&
          End If
        'If NewPos > StartPos And SourceFile = DestinationFile Then
        If NewPos > StartPos Then
          'inversion
          xLong4 = xLong2
          Else
          xLong4 = xLong3
          End If
        If SetFilePointer(SourceFile, StartPos + xLong4, 0&, 0&) = -1& Then
          BinaryMoveFileDataEx = False
          xLong2 = 0&
          ElseIf ReadFile(SourceFile, ByVal xChar1, xLong1, 0&, ByVal 0&) = 0& Then
          BinaryMoveFileDataEx = False
          xLong2 = 0&
          ElseIf SetFilePointer(DestinationFile, NewPos + xLong4, 0&, 0&) = -1& Then
          BinaryMoveFileDataEx = False
          xLong2 = 0&
          Else
          If WriteFile(DestinationFile, ByVal xChar1, xLong1, 0&, ByVal 0&) = 0& Then
            BinaryMoveFileDataEx = False
            xLong2 = 0&
            End If
          End If
        xLong3 = xLong3 + xLong1
'        If Not ProgressTotal = 0& Then
        If Not ProgressTotal = 0# Then
          ctProgressB_SetValue ProgressControl, (ProgressStart + xLong3 / Size * ProgressWidth), ProgressTotal
          #If UpdateByDoEvents Then
            DoEventsEx_SleepPeriodical
            #Else
            UpdateWindow
            #End If
          End If
        'If BinaryMoveFileData_AbortCopying Then GoTo Rs1
        Loop Until xLong2 = 0&
      xChar1 = ""
      BinaryMoveFileDataEx = True
      End If
    End If
  End Function
