c# 读取 mfc CArchive序列化的二进制文件

 刚做了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();
            }
	}
     }
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值