[StructLayout(LayoutKind.Sequential)]
public struct array
{
[MarshalAs(UnmanagedType.U4)]
UInt32 _Begin;
[MarshalAs(UnmanagedType.U4)]
UInt32 _End;
[MarshalAs(UnmanagedType.U4)]
UInt32 _Allocated;
[MarshalAs(UnmanagedType.Struct)]
block _Block;
} [StructLayout(LayoutKind.Sequential)]
public struct block
{
[MarshalAs(UnmanagedType.U4)]
UInt32 Ptr;
[MarshalAs(UnmanagedType.U4)]
UInt32 Id;
}
[StructLayout(LayoutKind.Sequential)]
public struct notify
{
[MarshalAs(UnmanagedType.FunctionPtr)]
notifyfunc Func;
IntPtr This;
} [StructLayout(LayoutKind.Sequential)]
public struct context
{
[MarshalAs(UnmanagedType.I4)]
public int Version;//4
public IntPtr Wnd;//4
public IntPtr LoadModule;//4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]//20*2,
public array[] StrTable;
}
int a = Marshal.SizeOf( typeof(context) );//运行后这里a=68
通过计算应该为4+4+4+4+40=56.运行后结果为68,
为什么结果是68,我想得到56的结果应该怎么办?
public struct array
{
[MarshalAs(UnmanagedType.U4)]
UInt32 _Begin;
[MarshalAs(UnmanagedType.U4)]
UInt32 _End;
[MarshalAs(UnmanagedType.U4)]
UInt32 _Allocated;
[MarshalAs(UnmanagedType.Struct)]
block _Block;
} [StructLayout(LayoutKind.Sequential)]
public struct block
{
[MarshalAs(UnmanagedType.U4)]
UInt32 Ptr;
[MarshalAs(UnmanagedType.U4)]
UInt32 Id;
}
[StructLayout(LayoutKind.Sequential)]
public struct notify
{
[MarshalAs(UnmanagedType.FunctionPtr)]
notifyfunc Func;
IntPtr This;
} [StructLayout(LayoutKind.Sequential)]
public struct context
{
[MarshalAs(UnmanagedType.I4)]
public int Version;//4
public IntPtr Wnd;//4
public IntPtr LoadModule;//4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]//20*2,
public array[] StrTable;
}
int a = Marshal.SizeOf( typeof(context) );//运行后这里a=68
通过计算应该为4+4+4+4+40=56.运行后结果为68,
为什么结果是68,我想得到56的结果应该怎么办?
解决方案 »
- C#窗体求练习题....有木有??有木有??
- 问一下键盘钩子或者用户控件问题
- 如何用代码控制DataGridView的内容进行滚动?
- 反编译出一段类代码不知道是何用处??
- DataGrid的数据源指定为IList的问题
- 求Intel GMA 4500(M)(HD)移动版windows2003的显卡驱动
- 高手请进!windowsXp自动更新文件保存在本地机器的那个位置啊?
- Buttons里面如何自动打开回收站&&网上邻居呢
- 大年初一发个求助帖,C# WPF的问题
- 如何将一个二维数组存入到一个一维数组中?
- 使用Microsoft SQL Server Compact 3.5数据库写的程序出现问题
- 需要找一个IE浏览器控件,支持放大缩小功能的,像IE8那样的
64位,64(4+4(对齐)+8*2+20*2)你可以看一下IntPtr.Size
更正一下,通过手工计算应该是52的,还有调试跟踪IntPtr.Size = 4!
还有没有能够解答的?
C++里的话应该是编译器选项
C#不知道应该是那个directive
public struct context
{
[MarshalAs(UnmanagedType.I4)]
public int Version;//4
public IntPtr Wnd;//4
public IntPtr LoadModule;//4
//以上为前半截
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]//20*2,
public array[] StrTable;
//以上为后半截
} 如果只有前半截,长度就是12,只有后半截,长度就是40,两截都有,就是68,哈