2GB> Files (source)

Iniciado por cobein, 27 Mayo 2008, 08:56 AM

0 Miembros y 1 Visitante están viendo este tema.

cobein

Aca les dejo dos funciones para trabajar con archivos de tamaño superior a los 2GB.

Código (vb) [Seleccionar]

Private Const Bit31                         As Currency = 2147483647@
Private Const Bit32                         As Currency = 4294967295@

Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

Private Function GetFileSizeEx(ByVal hFile As Long) As Currency
    Dim lLow    As Long
    Dim lHigh   As Long
    lLow = GetFileSize(hFile, lHigh)
    Call ToLargeInt(GetFileSizeEx, lLow, lHigh)
End Function

Private Function SetFilePointerEx(ByVal hFile As Long, ByVal lDistanceToMove As Currency, ByVal dwMoveMethod As Long) As Currency
    Dim lLow    As Long
    Dim lHigh   As Long
   
    Call FromLargeInt(lDistanceToMove, lLow, lHigh)
    lLow = SetFilePointer(hFile, lLow, lHigh, dwMoveMethod)
    Call ToLargeInt(SetFilePointerEx, lLow, lHigh)
End Function

Private Sub FromLargeInt(ByVal cLargeInt As Currency, ByRef lLow As Long, ByRef lHigh As Long)
    Do Until cLargeInt < Bit32
        lHigh = lHigh + 1
        cLargeInt = cLargeInt - Bit32
    Loop
    If cLargeInt > Bit31 Then
        lLow = -CLng(Bit32 - (cLargeInt - 1))
    Else
        lLow = CLng(cLargeInt)
    End If
End Sub

Private Sub ToLargeInt(ByRef cLargeInt As Currency, ByVal lLow As Long, ByVal lHigh As Long)
    cLargeInt = Bit32 * lHigh
    If lLow < 0 Then
        cLargeInt = cLargeInt + (Bit32 + (lLow + 1))
    Else
        cLargeInt = cLargeInt + lLow
    End If
End Sub

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.