下面是我试图从 c++ 转换为 c# 的代码
struct PSB {
short type_of_psb;
short call_dependent;
int32 del_psb_status;
uint32 seq_number[2];
int32 uma_psb_status;
short psb_reserved[6];
}
以前,我写了下面的结构。
[StructLayout(LayoutKind.Explicit)]
public struct PSB
{
[FieldOffset(0)]
public short type_of_psb;
[FieldOffset(2)]
public short call_dependent;
[FieldOffset(4)]
public int del_psb_status;
[FieldOffset(8)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public uint32 seq_number; // Here is the problem
[FieldOffset(16)]
public int uma_psb_status;
[FieldOffset(20)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public short[] psb_reserved;
}
但上面的 c# 代码不起作用,问题出在成员seq_number
所以我把它改成了
public ulong seq_number
从uint seq_number
,我删除了上述 marshalas 属性。
现在它正在使用遗留代码。我不知道为什么?如果我将 like 定义为 array 有什么问题?