刚做了c#读取CArchive序列化的二进制文件,其中的转换关系在此记录,以待以后需要的时候翻阅。其中有错误的希望大家能提出来。
public void ReadFormatIndexInFile()
{
try
{
System.IO.FileStream fs = new System.IO.FileStream("E:\\WORK\\test.ela", System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (BinaryReader br = new BinaryReader(fs))
{
/********文件开头部分*********/
string str = br.ReadString(); //标记 对应mfc CString
int nMainVer = br.ReadUInt16();//版本号 对应mfc WORD
int nSubVer = br.ReadUInt16();//版本号
int tmLoaded = (int)br.ReadUInt32();//导入时间 对应 mfc CTime
List<Byte> patrbyte = new List<Byte>(); // 对应于mfc CByteArray 数组
int Count = br.ReadUInt16();
for (int j = 0; j < Count; j++)
{
patrbyte.Add((byte)br.ReadByte());
}
List<UInt16> Caronizitions = new List<UInt16>(); // 对应于mfc CWordArray 数组
Count = br.ReadUInt16();
for (int j = 0; j < Count; j++)
{
Caronizitions.Add(br.ReadUInt16());
}
Count = br.ReadUInt16();// 对应于 mfc CStringArray
for (int j = 0; j < Count; j++)
{
br.ReadString();
}
Count = br.ReadUInt16();// 对应于 mfc CDWordArray
for (int j = 0; j < Count; j++)
{
br.ReadUInt32();
}
}
}
}