) As Long Dim fl As Long If m_LastBuff = False Then If m_OffSet = MAX_FILE_BUFF Then fl = ReadFileToBuff Select Case fl Case 0 GetByte = 0 Case -1 GetByte = -1 Case Else ch = m_fb(0) m_OffSet = 1 GetByte = 1 End Select Else ch = m_fb(m_OffSet) m_OffSet = m_OffSet + 1 GetByte = 1 End If Else If m_OffSet < m_MaxBytes Then ch = m_fb(m_OffSet) m_OffSet = m_OffSet + 1 GetByte = 1 Else ch = EOF_CHAR GetByte = 0 End If End If
End Function ''''写一个字节,如果正确表示1,错误为-1 Public Function PutByte(by As Byte) As Long If m_OffSet < MAX_FILE_BUFF Then
WriteBuffToFile m_fb(0) = by m_OffSet = 1 m_DirtyFlag = True
End If End Function ''''看当前指针是否到达文件最尾端 Public Function FEof() As Boolean If m_LastBuff = False Then FEof = False Else If m_OffSet = m_MaxBytes Then FEof = True Else FEof = False End If End If End Function ''''/////////////////////////////////////////////////////////////////////////////////////// ''''预读字节到缓冲区,并返回实际读到的字节,如果返回-1,则表示出错了。 Private Function ReadFileToBuff() As Long Dim dwReadNum As Long
If ReadFile(m_Handle, m_fb(0), MAX_FILE_BUFF, dwReadNum, 0) = 0 Then ReadFileToBuff = -1 Else If dwReadNum <> MAX_FILE_BUFF Then ''''最后一个缓冲区
End If End Function ''''写缓冲区到文件,并返回实际写的字节数 Private Function WriteBuffToFile() As Long Dim dwWriteNum As Long
If m_OffSet = 0 Or m_DirtyFlag = False Then ''''如果写入数为0或者写入标志错则不写入 WriteBuffToFile = 0 Else If WriteFile(m_Handle, m_fb(0), m_OffSet, dwWriteNum, 0) Then WriteBuffToFile = dwWriteNum Else WriteBuffToFile = -1 ''''出错 End If End If