Results 1 to 12 of 12

Thread: Binary Get# causes overflow on 10gb files [resolved]

Threaded View

  1. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Binary Get# causes overflow on 10gb files

    OK I understand now what you need. Unfortunatly VB natively doesn't offer this since even the Seek statement uses a Long to position the file pointer. So you have to turn to the API. You need to open the file using CreateFile in the same manner as you're already doing to get the file size. Next you need to call the SetFilePointer function. This function takes two Long values to simulate a 64-bit long integer to position the file pointer. However the low order Long is passed ByVal and for this to work you would need to pass an unsigned long to this argument, and as you know VB doesn't support unsigned long integers. So the solution would be to make several calls to SetFilePointer and move it (at the most) 2GB each time from the current position. You can then use the ReadFile function to read the number of bytes you need. So you should read this into a byte array instead of a string. You can then convert the byte array into a string using the StrConv function.
    VB Code:
    1. Private Declare Function SetFilePointer Lib "kernel32.dll" ( _
    2.  ByVal hFile As Long, _
    3.  ByVal lDistanceToMove As Long, _
    4.  ByRef lpDistanceToMoveHigh As Long, _
    5.  ByVal dwMoveMethod As Long) As Long
    6.  
    7. Private Declare Function ReadFile Lib "kernel32.dll" ( _
    8.  ByVal hFile As Long, _
    9.  ByRef lpBuffer As Any, _
    10.  ByVal nNumberOfBytesToRead As Long, _
    11.  ByRef lpNumberOfBytesRead As Long, _
    12.  ByRef lpOverlapped As Any) As Long
    13.  
    14. 'constant values that can be used in the dwMoveMethod argument of SetFilePointer
    15. Private Const FILE_BEGIN As Long = 0
    16. Private Const FILE_CURRENT As Long = 1
    17. Private Const FILE_END As Long = 2
    18.  
    19. [b]'I have skipped the declaration of CreateFile and CloseHandle since you already have them [/b]
    20.  
    21. Public Function GetDbl(strFileName As String, dblPos As Double) As String
    22.     Dim hFile As Long, bArr() As Byte
    23.     Dim nBytesRead As Long
    24.     hFile = CreateFile(strFileName, GENERIC_READ, FILE_SHARE_READ, _
    25.      ByVal 0&, OPEN_EXISTING, ByVal 0&, ByVal 0&)
    26.     Do While dblPos > &H7FFFFFFF '= 2147483647
    27.         Call SetFilePointer(hFile, &H7FFFFFFF, ByVal 0&, FILE_CURRENT)
    28.         dblPos = dblPos - &H7FFFFFFF
    29.     Loop
    30.     If CLng(dblPos) Then
    31.         Call SetFilePointer(hFile, CLng(dblPos), ByVal 0&, FILE_CURRENT)
    32.     End If
    33.     Redim bArr(3999) As Byte 'arrays are zero based so this is 4000 bytes
    34.     Call ReadFile(hFile, bArr(0), 4000, nBytesRead, ByVal 0&)
    35.     Call CloseHandle(hFile)
    36.     GetDbl = StrConv(bArr, vbUnicode)
    37. End Function
    Last edited by Joacim Andersson; Sep 8th, 2005 at 11:04 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width