慕桂英4014372
public struct dash_generic_param
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public short[] raw_data;
}
//public struct dash_generic_param
//{
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
// public ushort[] values;
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
// public ushort[] reserved;
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
// public ushort[] limit;
//}
// 结构体按你需求,2选1
public struct DashParamPacket {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 34)]
public ushort[] raw_data;
}
//public struct DashParamPacket {
// public ushort pre_id;
// public byte token;
// public byte r1;
// public dash_generic_param data;
// public byte major_id;
// public byte minor_id;
// public ushort r2;
//}
// 例如c++库里接口名为GetPacket,DashParamPacket是c#定义的与C++中内存对齐的结构体
[DllImport("xxx.dll")]
public static extern bool GetPacket(ref DashParamPacket parm);
static void Main(string[] args)
{
DashParamPacket param = new DashParamPacket(); // C#里的结构体
GetPacket(ref param); // 如果C++接口定义的结构体指针,可以直接用引用
// 如果需要转void*使用,可以用marhal库来回转
IntPtr p = In