You can't do anything with a file of 2 GB or more in size.
VB6 is a 32-bit application and simply cannot work with files that big.
Regards, Phill W.
what? *smacks forehead* why would anyone load a full 2GB file into memory. That's insane.
Especially when all the Hash routines work on streams, where you can feed it chunks of bytes.
You don't even do that in .NET... or do you?
A readymade solution is available in vbRichClient5, where you can (after checking in the Reference into the Project),
e.g. simply type in the VB-ImmediateWindow:
The cFSO.GetFileHash-Call supports HugeFiles - as well as all kind of Hash-Algos -
but it runs synchronously (without any intermediate Events).
So one might run it (for large Files>2GB) asynchronously on its own Thread, which is also supported like that
(into an otherwise empty Form, in a Project with a vbRichClient5-reference):
Code:
Option Explicit
Private WithEvents TH As cThreadHandler
Private Sub Form_Click()
Dim FileName As String
FileName = New_c.FSO.ShowOpenDialog
If Len(FileName) Then GetFileHashAsync FileName, CALG_MD5
End Sub
Private Sub GetFileHashAsync(FileName As String, ByVal Algo As enmHashAlgorithm)
If Not TH Is Nothing Then MsgBox "Thread for: " & TH.ThreadKey & " is still running": Exit Sub
Set TH = New_c.RegFree.ThreadObjectCreate(New_c.FSO.GetFileNameFromFullPath(FileName), "New_c", "FSO")
TH.CallAsync "GetFileHash", FileName, CALG_MD5
End Sub
Private Sub TH_MethodFinished(MethodName As String, Result As Variant, ErrString As String, ErrSource As String, ByVal ErrNumber As Long)
Debug.Print MethodName, TH.ThreadKey, Result
Set TH = Nothing
End Sub
@Olaf: He has also placed a progress bar on the form. That would probably has to be PBS_MARQUEE with no percentage indicator.
Yep...
In case the FileSize is above a certain margin, one could retrieve the rate of the achievable "MegaBytes-per-second" priorily though,
e.g. on an empty ByteArray of for example 50-100MB, using the same Hash-Algo over the RC5-cCrypt-Class...
This way one could calculate a rough approximation of an "expected finish-time"...
Though if the whole thing is more or less a hobby-project (for private purposes),
then the "Marquee-Mode" would probably be sufficient.
edit: HAHAHA. As seen from the screenshot, it seems the OP already copied dilettante's MD5Hash example.
*shrugs*
maybe the OP will let us know if dilettante's code or my update works
Code:
Public Function HashFile(ByVal FileName As String) As String
Const CHUNK As Long = 16384
Dim HugeFile As HugeBinaryFile
Dim cyWholeChunks As Currency
Dim lngRemainder As Long
Dim cyChunk As Currency
Dim bytBlock() As Byte
On Error Resume Next 'Does file exist?
GetAttr FileName
If Err.Number = 0 Then
On Error GoTo 0
Set HugeFile = New HugeBinaryFile
HugeFile.OpenFile FileName
cyWholeChunks = Int(HugeFile.FileLen / CHUNK)
lngRemainder = HugeFile.FileLen - (CHUNK * cyWholeChunks)
NewHash
ReDim bytBlock(CHUNK - 1)
For cyChunk = 1 To cyWholeChunks
HugeFile.ReadBytes bytBlock
HashBlock bytBlock
Next
If lngRemainder > 0 Then
ReDim bytBlock(lngRemainder - 1)
HugeFile.ReadBytes bytBlock
HashBlock bytBlock
End If
HugeFile.CloseFile
HashFile = HashValue()
Else
Err.Raise vbObjectError Or &HC342&, _
"MD5Hash.HashFile", _
"File doesn't exist"
End If
End Function
Last edited by DEXWERX; Oct 24th, 2017 at 01:01 PM.