首页 > 解决方案 > 正确的结构编组

问题描述

我有一个结构:

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 属性设置正确的元帅属性吗?

标签: c#structmarshalling

解决方案


LPUSHORT只是指向ushort值的长指针。您可以将其编组为IntPtr使用Marshal.ReadInt16or读取值Marshal.ReadInt32(因为您使用的是 unsigned short)。本文描述了另一种选择,Unmanaged to Managed type translation table例如编组LP<struct>[In] ref <struct>


推荐阅读