Reputation: 35
I'm wondering if this c structure I've translated to Delphi is incorrect, and if incorrect, how it can be translated properly? Since the union is mid structure it seems it's not as simple to convert this properly. Any help would be much appreciated
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;
Upvotes: 1
Views: 235
Reputation: 26376
Just fold the fields after the CASE block into one of the branches (preferably the largest one)
Declaring a separate record would require changing the way you access it.
P.s. not entirely mine, see Rudy Velthuis' site, http://rvelthuis.de/articles/articles-convert.html
Upvotes: 1
Reputation: 613352
A variant part of a record has to appear at the end of a record, in Delphi. Because this union appears in the middle of the struct, you will need to declare the union as a separate type in Delphi and then use it in the containing record.
Upvotes: 2