用int *成员将C ++结构编组为C#
我有一个C ++结构如下:
struct CTMDeviceError {
struct CTMDeviceInfo sDeviceInfo;
int32_t iResultCode;
int32_t iExtendedResultCode;
int32_t * piDenomination;
int32_t * piChangeDue;
};
我创建了一个等效的c#结构,但是我无法编组int32 *类型。
[StructLayout(LayoutKind.Sequential)]
public struct CTMDeviceError
{
public CTMDeviceInfo deviceInfo;
[MarshalAs(UnmanagedType.I4)]
public Int32 resultCode;
[MarshalAs(UnmanagedType.I4)]
public Int32 extendedResultCode;
public ??? denomination;
public ??? changeDue;
};
我曾尝试使用IntPtr或Int32 [],但Visual Studio显示不匹配错误。 我可以请一些建议吗? 谢谢!
这是结构细节的其余部分:
C ++
struct CTMDeviceInfo {
enum CTMDeviceType eDeviceType;
char * szDeviceModel;
char * szDeviceSubModel;
int32_t * piDeviceID;
};
enum CTMDeviceType {
CTM_DEVICETYPE_CASHCHANGER = 5,
CTM_DEVICETYPE_CASHACCEPTOR = 15,
CTM_DEVICETYPE_COINACCEPTOR = 16,
CTM_DEVICETYPE_OTHER = 17
};
C#
[StructLayout(LayoutKind.Sequential)]
public struct CTMDeviceInfo
{
public CTMDeviceType deviceType;
[MarshalAs(UnmanagedType.LPStr)]
public string deviceModel;
[MarshalAs(UnmanagedType.LPStr)]
public string deviceSubModel;
public ??? deviceId;
};
public enum CTMDeviceType
{
CTM_DEVICETYPE_CASHCHANGER = 5,
CTM_DEVICETYPE_CASHACCEPTOR = 15,
CTM_DEVICETYPE_COINACCEPTOR = 16,
CTM_DEVICETYPE_OTHER = 17
};
指针的类型应该是System.IntPtr
。