c# - 正确的结构编组
问题描述
我有一个结构:
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 属性设置正确的元帅属性吗?
解决方案
LPUSHORT
只是指向ushort
值的长指针。您可以将其编组为IntPtr
使用Marshal.ReadInt16
or读取值Marshal.ReadInt32
(因为您使用的是 unsigned short)。本文描述了另一种选择,Unmanaged to Managed type translation table
例如编组LP<struct>
到[In] ref <struct>
推荐阅读
- javascript - 在 Jquery 的循环内移动 Div
- amazon-web-services - 为什么 AWS ec2 实例会降级?
- python - 运行泊坞窗图像给出 - 无法找到图像错误
- reactjs - 无法解决 'react-horizontal-scrolling-menu/build/scrollMenu'
- spring - 从数据库中读取@Transient 字段
- jboss7.x - JBoss EAP 7.2.8 中的 EJB2.1 查找问题
- javascript - 使用异步执行一个又一个功能并在反应中等待
- typescript - 离子+电容器:运动在设备上不起作用
- javascript - 意外令牌 | 将 PHP 数组解析为 JavaScript
- javascript - 不以特定单词结尾的正则表达式