[StructLayout(LayoutKind.Explicit,Pack=1,CharSet=CharSet.Unicode,Size=64+2)]
public unsafe struct Repository
{
/// <summary>
/// 仓库名称
/// </summary>
[FieldOffset(0)]
[MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
public fixed byte Name[32]; //加上fixed就可以使用c语言语法的数组
/// <summary>
/// 指针
/// </summary>
[FieldOffset(64)]
public ushort location;
第二种定义方法
public unsafe struct MemoryInfo
{
public UInt32 ModuleSize;
public UInt32 EntryPoint;
public UInt64 VirtualAddress;
public bool Readable;
public bool Writeable;
public bool Executeable;
public bool Guardable;
//如果使用char 占用字节会翻倍 使用bute就是真实大小
public fixed byte ModulePath[260];
};
获取结构体大小
System.Runtime.InteropServices.Marshal.SizeOf(typeof(MemoryInfo))