'Filename : Checksum CRC32.cls (cCRC32 Class Module)
'Description : Calculate CRC32 Checksum of a file or string
'Date : Tuesday, March 01, 2005, 06:13 PM
'Last Update : Friday, November 25, 2005, 12:18 AM
'You can freely use and distribute this class or upload these codes on any site
'provided that the original credits are kept unmodified.
'Credits goes to:
'Fredrik Qvarfort ⌐ 2000, CRC Checksum Class using a precompiled assembler code
'API Declaration
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Variable Declarations
Private m_CRC32Asmbl() As Byte
Private m_CRC32Table(0 To 255) As Long
'//--Procedures--//
Function FileChecksum(File As String) As String
'Returns the CRC32 checksum value of a specified file.
'Make sure the file isn't empty or invalid to avoid errors later
If Len(Dir$(File)) = 0 Then
Exit Function
End If
On Error GoTo Err_Handler
Dim Arr() As Byte
Dim f As Integer
f = FreeFile 'Get any available file number for use
Open File For Binary Access Read As f
'Redimensionized array according to length of file
ReDim Arr(0 To LOF(f) - 1) As Byte
Get #f, , Arr() 'Get file contents
Close #f
'Calculate CRC32 checksum
FileChecksum = Hex$(CalculateBytes(Arr))
Err_Handler:
End Function
Function StringChecksum(Str As String) As String
'Returns the CRC32 checksum value of the specified string.
'Make sure the string has contents before execution to avoid errors