Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: cobein en 27 Mayo 2008, 08:56 am



Título: 2GB> Files (source)
Publicado por: cobein en 27 Mayo 2008, 08:56 am
Aca les dejo dos funciones para trabajar con archivos de tamaño superior a los 2GB.

Código
  1. Private Const Bit31                         As Currency = 2147483647@
  2. Private Const Bit32                         As Currency = 4294967295@
  3.  
  4. Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
  5. Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  6.  
  7. Private Function GetFileSizeEx(ByVal hFile As Long) As Currency
  8.    Dim lLow    As Long
  9.    Dim lHigh   As Long
  10.    lLow = GetFileSize(hFile, lHigh)
  11.    Call ToLargeInt(GetFileSizeEx, lLow, lHigh)
  12. End Function
  13.  
  14. Private Function SetFilePointerEx(ByVal hFile As Long, ByVal lDistanceToMove As Currency, ByVal dwMoveMethod As Long) As Currency
  15.    Dim lLow    As Long
  16.    Dim lHigh   As Long
  17.  
  18.    Call FromLargeInt(lDistanceToMove, lLow, lHigh)
  19.    lLow = SetFilePointer(hFile, lLow, lHigh, dwMoveMethod)
  20.    Call ToLargeInt(SetFilePointerEx, lLow, lHigh)
  21. End Function
  22.  
  23. Private Sub FromLargeInt(ByVal cLargeInt As Currency, ByRef lLow As Long, ByRef lHigh As Long)
  24.    Do Until cLargeInt < Bit32
  25.        lHigh = lHigh + 1
  26.        cLargeInt = cLargeInt - Bit32
  27.    Loop
  28.    If cLargeInt > Bit31 Then
  29.        lLow = -CLng(Bit32 - (cLargeInt - 1))
  30.    Else
  31.        lLow = CLng(cLargeInt)
  32.    End If
  33. End Sub
  34.  
  35. Private Sub ToLargeInt(ByRef cLargeInt As Currency, ByVal lLow As Long, ByVal lHigh As Long)
  36.    cLargeInt = Bit32 * lHigh
  37.    If lLow < 0 Then
  38.        cLargeInt = cLargeInt + (Bit32 + (lLow + 1))
  39.    Else
  40.        cLargeInt = cLargeInt + lLow
  41.    End If
  42. End Sub
  43.  
  44.