我需要将一个复杂的C ++结构转换为C#结构,我已经在C#中转换了其他结构,这个包含一些二维数组,这是怎么改变它的问题,这是我的结构,
这是我正确转换的其他结构,
C ++:
typedef struct
{
BYTE sSerialNumber[DH_SERIALNO_LEN]; BYTE byAlarmInPortNum;
BYTE byAlarmOutPortNum;
BYTE byDiskNum;
BYTE byDVRType;
BYTE byChanNum;
} NET_DEVICEINFO, *LPNET_DEVICEINFO;
C#:
public struct NET_DEVICEINFO
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
public byte[] sSerialNumber;
public byte byAlarmInPortNum;
public byte byAlarmOutPortNum;
public byte byDiskNum;
public byte byDVRType;
public byte byChanNum;
}
这个结构我想转换,这有2个暗淡的数组 C ++:
typedef struct
{
DWORD dwSize;
DWORD dwDecProListNum;
char DecProName[DH_MAX_DECPRO_LIST_SIZE][DH_MAX_NAME_LEN];
DH_485_CFG stDecoder[DH_MAX_DECODER_NUM];
DWORD dw232FuncNameNum;
char s232FuncName[DH_MAX_232FUNCS][DH_MAX_NAME_LEN];
DH_RS232_CFG st232[DH_MAX_232_NUM];
} DHDEV_COMM_CFG;
这是我在C#中的尝试,但它给了我一个错误, C#:
[StructLayout(LayoutKind.Sequential, Pack = 2, CharSet = CharSet.Auto)]
public struct DHDEV_COMM_CFG
{
public uint dwSize;
public uint dwDecProListNum;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
public string[] DecProName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
DH_485_CFG[] stDecoder;
public uint dw232FuncNameNum;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public string[] s232FuncName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public DH_RS232_CFG[] st232;
} ;
请告诉我该怎么做....
By Bala