将带联合的 c 结构转换为 Delphi 记录
Converting c structure with union to Delphi record
我想知道我翻译成 Delphi 的这个 c 结构是否不正确,如果不正确,如何正确翻译?由于 union 是中间结构,因此正确转换它似乎并不那么简单。任何帮助将不胜感激
typedef struct FWPM_FILTER0_ {
GUID filterKey;
FWPM_DISPLAY_DATA0 displayData;
UINT32 flags;
GUID *providerKey;
FWP_BYTE_BLOB providerData;
GUID layerKey;
GUID subLayerKey;
FWP_VALUE0 weight;
UINT32 numFilterConditions;
FWPM_FILTER_CONDITION0 *filterCondition;
FWPM_ACTION0 action;
union {
UINT64 rawContext;
GUID providerContextKey;
};
GUID *reserved;
UINT64 filterId;
FWP_VALUE0 effectiveWeight;
} FWPM_FILTER0;
type
FWPM_FILTER0 = record
filterKey: TGUID;
displayData: FWPM_DISPLAY_DATA0;
flags: UINT32;
providerKey: PGUID;
providerData: FWP_BYTE_BLOB;
layerKey: TGUID;
subLayerKey: TGUID;
weight: FWP_VALUE0;
numFilterConditions: UINT32;
filterCondition: PFWPM_FILTER_CONDITION0;
action: FWPM_ACTION0;
case Integer of
0: (rawContext: UINT64);
1: (providerContextKey: TGUID;
reserved: PGUID;
filterId: UINT64;
effectiveWeight: FWP_VALUE0);
end;
记录的变体部分必须出现在记录的末尾,在 Delphi 中。由于此联合出现在结构的中间,因此您需要在 Delphi 中将联合声明为单独的类型,然后在包含的记录中使用它。
只需将 CASE 块之后的字段折叠到分支之一(最好是最大的分支)
声明单独的记录需要更改您访问它的方式。
P.s。不完全是我的,请参阅 Rudy Velthuis 的网站,http://rvelthuis.de/articles/articles-convert.html
我想知道我翻译成 Delphi 的这个 c 结构是否不正确,如果不正确,如何正确翻译?由于 union 是中间结构,因此正确转换它似乎并不那么简单。任何帮助将不胜感激
typedef struct FWPM_FILTER0_ {
GUID filterKey;
FWPM_DISPLAY_DATA0 displayData;
UINT32 flags;
GUID *providerKey;
FWP_BYTE_BLOB providerData;
GUID layerKey;
GUID subLayerKey;
FWP_VALUE0 weight;
UINT32 numFilterConditions;
FWPM_FILTER_CONDITION0 *filterCondition;
FWPM_ACTION0 action;
union {
UINT64 rawContext;
GUID providerContextKey;
};
GUID *reserved;
UINT64 filterId;
FWP_VALUE0 effectiveWeight;
} FWPM_FILTER0;
type
FWPM_FILTER0 = record
filterKey: TGUID;
displayData: FWPM_DISPLAY_DATA0;
flags: UINT32;
providerKey: PGUID;
providerData: FWP_BYTE_BLOB;
layerKey: TGUID;
subLayerKey: TGUID;
weight: FWP_VALUE0;
numFilterConditions: UINT32;
filterCondition: PFWPM_FILTER_CONDITION0;
action: FWPM_ACTION0;
case Integer of
0: (rawContext: UINT64);
1: (providerContextKey: TGUID;
reserved: PGUID;
filterId: UINT64;
effectiveWeight: FWP_VALUE0);
end;
记录的变体部分必须出现在记录的末尾,在 Delphi 中。由于此联合出现在结构的中间,因此您需要在 Delphi 中将联合声明为单独的类型,然后在包含的记录中使用它。
只需将 CASE 块之后的字段折叠到分支之一(最好是最大的分支)
声明单独的记录需要更改您访问它的方式。
P.s。不完全是我的,请参阅 Rudy Velthuis 的网站,http://rvelthuis.de/articles/articles-convert.html