Public Property Get IsReadAccess() As Boolean
If hFile = 0 Then Exit Property
IsReadAccess = CBool(tmpGeneric And GENERIC_READ)
End Property
Public Property Get IsWriteAccess() As Boolean
If hFile = 0 Then Exit Property
IfWriteAccess = CBool(tmpGeneric And GENERIC_WRITE)
End Property
Public Property Get FileName() As String
FileName = tmpFileName
End Property
Public Property Let FileName(ByVal sFilename As String)
If sFilename = "" Then Exit Property
If Len(sFilename) > MAX_PATH Then Exit Property
If hFile <> INVALID_HANDLE_VALUE Then
FileClose
End If
FileOpen sFilename
End Property
Public Property Get LoSeekPointer() As Long
LoSeekPointer = mySeekPtr.Lolong
End Property
Public Property Get HiSeekPointer() As Long
HiSeekPointer = mySeekPtr.HiLong
End Property
Public Sub LSeek(ByVal Lolong As Long, ByVal HiLong As Long)
If hFile = INVALID_HANDLE_VALUE Then Exit Sub
RaiseEvent BevoreFileSeek(hFile, mySeekPtr.Lolong, mySeekPtr.HiLong)
mySeekPtr.Lolong = SetFilePointer(hFile, Lolong, HiLong, FILE_CURRENT)
mySeekPtr.HiLong = HiLong
RaiseEvent AfterFileSeek(hFile, mySeekPtr.Lolong, mySeekPtr.HiLong)
End Sub
Public Function LGet(ByVal nLen As Long) As String
Dim sRead As String
Dim nRetVal As Long
If hFile = INVALID_HANDLE_VALUE Then Exit Function
sRead = Space(nLen)
ReadFile hFile, sRead, Len(sRead), nRetVal, 0
LGet = sRead
End Function
Public Sub FileOpen(ByVal sFilename As String, Optional ByVal nCreate As _
CreateFlags, Optional ByVal nGeneric As Long, Optional ByVal nShare As Long)
Dim sa As SECURITY_ATTRIBUTES
If sFilename = "" Then Exit Sub
If Len(sFilename) > MAX_PATH Then Exit Sub
If hFile <> INVALID_HANDLE_VALUE Then
FileClose
End If
If nCreate > 0 Then tmpCreate = nCreate
If nGeneric > 0 Then tmpGeneric = nGeneric
If nShare > 0 Then tmpShare = nShare
hFile = CreateFile(sFilename, tmpGeneric, tmpShare, sa, tmpCreate, 0, ByVal _
0)
If hFile <> INVALID_HANDLE_VALUE Then
RaiseEvent FileOpen(hFile)
mySeekPtr.Lolong = 1
mySeekPtr.HiLong = 0
End If
End Sub
Public Sub FileClose()
If hFile = INVALID_HANDLE_VALUE Then Exit Sub
RaiseEvent FileClose(hFile)
CloseHandle hFile
hFile = INVALID_HANDLE_VALUE
tmpCreate = 0
End Sub
Public Function SeekAndGet(ByVal lolng As Long, ByVal HiLong As Long, ByVal _
nLen As Long) As String
Dim sRead As String
Dim nRetVal As Long
If hFile = INVALID_HANDLE_VALUE Then Exit Function
RaiseEvent BevoreFileSeek(hFile, mySeekPtr.Lolong, mySeekPtr.HiLong)
mySeekPtr.Lolong = SetFilePointer(hFile, nLen, HiLong, FILE_CURRENT)
mySeekPtr.HiLong = HiLong
sRead = Space(nLen)
ReadFile hFile, sRead, Len(sRead), nRetVal, 0
RaiseEvent AfterFileSeek(hFile, mySeekPtr.Lolong, mySeekPtr.HiLong)
SeekAndGet = sRead
End Function
Public Property Get GetLoFileSize() As Long
Dim hLong
If hFile = INVALID_HANDLE_VALUE Then Exit Property
GetLoFileSize = GetFileSize(hFile, hLong)
End Property
Public Property Get GetHiFileSize() As Long
Dim hLong
If hFile = INVALID_HANDLE_VALUE Then Exit Property
GetFileSize hFile, hLong
GetHiFileSize = hLong
End Property
Private Sub Class_Terminate()
If hFile <> INVALID_HANDLE_VALUE Then CloseHandle hFile
End Sub |