public struct ItemInfo
{
public int ? postion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public char[] id ;
public int ? StartUnitPos;
public int ? HaveUnit;
public int ? ValueSize;
public int ? PreValuePos;
public int ? BackValuePos;
public int ? flag;
private int reserve; public ItemInfo( int ? n )
{
id = new char[512];
postion = n ;
StartUnitPos = n;
HaveUnit = n;
ValueSize = n;
PreValuePos = n;
BackValuePos = n;
flag = n;
reserve = 0;
}
}....protected ItemInfo ii = new ItemInfo(null);MessageBox.Show(string.Format("{0:d}", Marshal.SizeOf(ii)));以前没用[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]时,得出数字是64,这是因为没有把数组占用空间算上。现在我指定了数组元素个数,可得出结果是572!不对啊!C# char是unicode字符,一个占两个字节,按理说应是1084啊!晕。晕。请高手指点!
{
public int ? postion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public char[] id ;
public int ? StartUnitPos;
public int ? HaveUnit;
public int ? ValueSize;
public int ? PreValuePos;
public int ? BackValuePos;
public int ? flag;
private int reserve; public ItemInfo( int ? n )
{
id = new char[512];
postion = n ;
StartUnitPos = n;
HaveUnit = n;
ValueSize = n;
PreValuePos = n;
BackValuePos = n;
flag = n;
reserve = 0;
}
}....protected ItemInfo ii = new ItemInfo(null);MessageBox.Show(string.Format("{0:d}", Marshal.SizeOf(ii)));以前没用[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]时,得出数字是64,这是因为没有把数组占用空间算上。现在我指定了数组元素个数,可得出结果是572!不对啊!C# char是unicode字符,一个占两个字节,按理说应是1084啊!晕。晕。请高手指点!
解决方案 »
- 大家都说说当调试时遇到错误都咋办?
- 有没有利用agsXMPP协议开发即时通讯的高手
- 求助在线等!!!!!!
- 菜鸟求指教
- 菜鸟求助-课设-windows窗口应用程序连接mysql数据库问题-大神帮帮忙
- 一个简单的XML操作问题
- 用ASP.NET 的RangeValidator 验证控件..用什么来表示输入小于15个汉字呀!!!!!!怎样表达
- 获取不到dropdownlist 的值
- 一个最初级的网络编程问题
- C#高手与微软工程师哪里去了?
- 请问怎样写一个错误处理模块,让整个项目中可以通过它自动检查到错误并提示,不用在每一个地方写try{} catch()等
- 如何编程实现将Excel表数据导入SQL Server 2000数据库
不过用时如何把int[] id ;转换为char[] id ; ?
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct ItemInfo
{
public int postion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public char[] id;
public int StartUnitPos;
public int HaveUnit;
public int ValueSize;
public int PreValuePos;
public int BackValuePos;
public int flag;
private int reserve; public ItemInfo(int n)
{
postion = n ;
id = new char[512];
StartUnitPos = n;
HaveUnit = n;
ValueSize = n;
PreValuePos = n;
BackValuePos = n;
flag = n;
reserve = 0;
}
}