加为好友
发送私信
在线聊天
zswang
等级:
可用分等级:小财主
总技术专家分:119969
总技术专家分排名:35
发表于:2008-08-23 23:03:03 18 楼 得分:10
这个文件打开分析了下,有五段数据,每段44字节: 详情 01 1F 00 40 00 00 00 00 00 00 59 40 00 00 00 00 00 40 8F 40 00 00 00 00 00 40 8F 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 C0 62 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 34 00 40 01 00 00 00 03 00 00 00 00 00 00 00 00 C0 82 40 3B 70 CE 88 D2 73 8D 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 79 40 00 00 00 00 00 C0 82 40 00 00 00 00 00 00 89 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 1F 00 40 00 00 00 00 00 E0 85 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 34 00 40 04 00 00 00 1(char)+5*8(double)=41 看来多3个字节,第一char对齐估计是4. C# code
[StructLayout(LayoutKind.Sequential, Pack = 4 )]
public class SECTION
{
public byte Type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5 )]
public double [] D5 = new double [ 5 ];
}
private void button2_Click( object sender, EventArgs e)
{
FileStream fileStream = new FileStream( @" c:\temp\123.HAL " ,
FileMode.Open, FileAccess.Read);
byte [] buffer = new byte [Marshal.SizeOf( typeof (SECTION))];
while (fileStream.Read(buffer, 0 , buffer.Length) >= buffer.Length)
{
SECTION section = new SECTION();
Marshal.PtrToStructure(
Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0 ), section);
Console.WriteLine(
" Type={0}, D5[0]={1}, D5[1]={2}, D5[2]={3}, D5[3]={4}, D5[4]={5} " ,
section.Type, section.D5[ 0 ], section.D5[ 1 ], section.D5[ 2 ],
section.D5[ 3 ], section.D5[ 4 ]);
}
fileStream.Close();
fileStream.Dispose();
}
输出 Type=1, D5[0]=100, D5[1]=1000, D5[2]=1000, D5[3]=0, D5[4]=0 Type=2, D5[0]=150, D5[1]=0, D5[2]=0, D5[3]=0, D5[4]=2.65250132361352E-314 Type=3, D5[0]=600, D5[1]=942.4778, D5[2]=0, D5[3]=0, D5[4]=0 Type=4, D5[0]=400, D5[1]=600, D5[2]=800, D5[3]=0, D5[4]=0 Type=2, D5[0]=700, D5[1]=0, D5[2]=0, D5[3]=0, D5[4]=9.01848869650934E-314
修改
删除
举报
引用
回复