[VB.NET]MFC CArchive的讀取
#Region “Config” Private ReadOnly BYTES_COUNT_IN_BOOL As Byte = 4 ‘VC6的BOOL佔 4 Bytes Private ReadOnly BYTES_COUNT_IN_INT As Byte = 4 ‘VC6的Int佔 4 Bytes Private ReadOnly BYTES_COUNT_IN_FLOAT As Byte = 4 ‘VC6的Float佔 4 Bytes Private ReadOnly BYTES_COUNT_IN_DOUBLE As Byte = 8 ‘VC6的Double佔 8 Bytes Private ReadOnly BUFFERSIZE As Integer = 512
#End Region
#Region “Private Var”
Private m_baryBinaryData(BUFFERSIZE) As Byte
Private m_fsFileStream As FileStream
Private m_nDataLength As Integer
Private m_strData As String
Private m_nData As Integer
Private m_sData As Single
Private m_dData As Double
Private m_bData As Boolean
#End Region
#Region “Constructer”
Public Sub New(ByVal FilePath As String)
m_fsFileStream = New FileStream(FilePath, FileMode.Open)
End Sub
#End Region
#Region “Public Method”
Public Function GetString() As String
m_nDataLength = m_fsFileStream.ReadByte
m_fsFileStream.Read(m_baryBinaryData, 0, m_nDataLength)
m_strData = Encoding.Default.GetString(m_baryBinaryData, 0, m_nDataLength)
Return m_strData
End Function
Public Function GetInt() As Integer
m_fsFileStream.Read(m_baryBinaryData, 0, BYTES_COUNT_IN_INT)
m_nData = BitConverter.ToInt32(m_baryBinaryData, 0)
Return m_nData
End Function
Public Function GetDouble() As Double
m_fsFileStream.Read(m_baryBinaryData, 0, BYTES_COUNT_IN_DOUBLE)
m_dData = BitConverter.ToDouble(m_baryBinaryData, 0)
Return m_dData
End Function
Public Function GetFloat() As Single
m_fsFileStream.Read(m_baryBinaryData, 0, BYTES_COUNT_IN_FLOAT)
m_sData = BitConverter.ToSingle(m_baryBinaryData, 0)
Return m_sData
End Function
Public Function GetBoolean() As Boolean
m_fsFileStream.Read(m_baryBinaryData, 0, BYTES_COUNT_IN_BOOL)
m_bData = BitConverter.ToBoolean(m_baryBinaryData, 0)
Return m_bData
End Function
#End Region
End Class