将带有联合的c结构转换为Delphi记录 [英] Converting c structure with union to Delphi record

查看:41
本文介绍了将带有联合的c结构转换为Delphi记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我翻译成 Delphi 的这个 c 结构是否不正确,如果不正确,如何正确翻译?由于工会是中间结构,因此正确转换它似乎并不那么简单.任何帮助将不胜感激

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;

推荐答案

在 Delphi 中,记录的变体部分必须出现在记录的末尾.因为这个联合出现在结构的中间,你需要在 Delphi 中将联合声明为一个单独的类型,然后在包含的记录中使用它.

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.

这篇关于将带有联合的c结构转换为Delphi记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆