正确的结构编组
Correct Structure Marshalling
我有一个结构:
typedef struct _wfs_bcr_caps
{
WORD wClass;
BOOL bCompound;
BOOL bCanFilterSymbologies;
LPUSHORT lpwSymbologies;
DWORD dwGuidLights[32];
LPSTR lpszExtra;
BOOL bPowerSaveControl;
BOOL bAntiFraudModule;
}
我需要在 C# 中正确复制此结构。
但我对 LPUSHORT 类型有疑问。有人可以帮助我为 lpwSymbologies 属性 设置正确的 marshal 属性吗?
LPUSHORT
只是指向 ushort
值的长指针。您可以将其编组为 IntPtr
,然后使用 Marshal.ReadInt16
或 Marshal.ReadInt32
读取一个值(因为您使用的是 unsigned short)。此 article、Unmanaged to Managed type translation table
中描述了另一个选项,例如将 LP<struct>
编组为 [In] ref <struct>
我有一个结构:
typedef struct _wfs_bcr_caps
{
WORD wClass;
BOOL bCompound;
BOOL bCanFilterSymbologies;
LPUSHORT lpwSymbologies;
DWORD dwGuidLights[32];
LPSTR lpszExtra;
BOOL bPowerSaveControl;
BOOL bAntiFraudModule;
}
我需要在 C# 中正确复制此结构。
但我对 LPUSHORT 类型有疑问。有人可以帮助我为 lpwSymbologies 属性 设置正确的 marshal 属性吗?
LPUSHORT
只是指向 ushort
值的长指针。您可以将其编组为 IntPtr
,然后使用 Marshal.ReadInt16
或 Marshal.ReadInt32
读取一个值(因为您使用的是 unsigned short)。此 article、Unmanaged to Managed type translation table
中描述了另一个选项,例如将 LP<struct>
编组为 [In] ref <struct>