Translation of Vista WinAPI C ++ for Delphi - any suggestions?

I need to call the Windows API function introduced in Vista from my Delphi application, but I don't have the Delphi headers that describe this function.

The related functions are already documented in the JEDI Windows API library, but not in this function.

My C ++ almost does not exist, and I'm struggling to determine the Delphi definitions corresponding to the function and its parameter, as described in MSDN.

From http://msdn.microsoft.com/en-us/library/aa814417.aspx

NETIOAPI_API GetIpInterfaceEntry(__inout  PMIB_IPINTERFACE_ROW Row);

typedef struct _MIB_IPINTERFACE_ROW {
  ADDRESS_FAMILY                 Family;
  NET_LUID                       InterfaceLuid;
  NET_IFINDEX                    InterfaceIndex;
  ULONG                          MaxReassemblySize;
  ULONG64                        InterfaceIdentifier;
  ULONG                          MinRouterAdvertisementInterval;
  ULONG                          MaxRouterAdvertisementInterval;
  BOOLEAN                        AdvertisingEnabled;
  BOOLEAN                        ForwardingEnabled;
  BOOLEAN                        WeakHostSend;
  BOOLEAN                        WeakHostReceive;
  BOOLEAN                        UseAutomaticMetric;
  BOOLEAN                        UseNeighborUnreachabilityDetection;
  BOOLEAN                        ManagedAddressConfigurationSupported;
  BOOLEAN                        OtherStatefulConfigurationSupported;
  BOOLEAN                        AdvertiseDefaultRoute;
  NL_ROUTER_DISCOVERY_BEHAVIOR   RouterDiscoveryBehavior;
  ULONG                          DadTransmits;
  ULONG                          BaseReachableTime;
  ULONG                          RetransmitTime;
  ULONG                          PathMtuDiscoveryTimeout;
  NL_LINK_LOCAL_ADDRESS_BEHAVIOR LinkLocalAddressBehavior;
  ULONG                          LinkLocalAddressTimeout;
  ULONG                          ZoneIndices[ScopeLevelCount];
  ULONG                          SitePrefixLength;
  ULONG                          Metric;
  ULONG                          NlMtu;
  BOOLEAN                        Connected;
  BOOLEAN                        SupportsWakeUpPatterns;
  BOOLEAN                        SupportsNeighborDiscovery;
  BOOLEAN                        SupportsRouterDiscovery;
  ULONG                          ReachableTime;
  NL_INTERFACE_OFFLOAD_ROD       TransmitOffload;
  NL_INTERFACE_OFFLOAD_ROD       ReceiveOffload;
  BOOLEAN                        DisableDefaultRoutes;
}MIB_IPINTERFACE_ROW, *PMIB_IPINTERFACE_ROW;

Among other bits, the bits I'm struggling with right now are the ZoneIndices [ScopeLevelCount] field; I can not decide what size should be an array.

, , ++. Windows DLL Vista .

type
  PMIB_IPINTERFACE_ROW = ^MIB_IPINTERFACE_ROW;
  {$EXTERNALSYM PMIB_IPINTERFACE_ROW}
  _MIB_IPINTERFACE_ROW = record
    Family: ADDRESS_FAMILY;
    InterfaceLuid: NET_LUID;
    InterfaceIndex: NET_IFINDEX;
    MaxReassemblySize,
    InterfaceIdentifier,
    MinRouterAdvertisementInterval,
    MaxRouterAdvertisementInterval: Cardinal;
    AdvertisingEnabled,
    ForwardingEnabled,
    WeakHostSend,
    WeakHostReceive,
    UseAutomaticMetric,
    UseNeighborUnreachabilityDetection,
    ManagedAddressConfigurationSupported,
    OtherStatefulConfigurationSupported,
    AdvertiseDefaultRoute: LongBool;
    RouterDiscoveryBehavior: NL_ROUTER_DISCOVERY_BEHAVIOR;
    DadTransmits,
    BaseReachableTime,
    RetransmitTime,
    PathMtuDiscoveryTimeout: Cardinal;
    LinkLocalAddressBehavior: NL_LINK_LOCAL_ADDRESS_BEHAVIOR;
    LinkLocalAddressTimeout,
    ZoneIndices[ScopeLevelCount],
    SitePrefixLength,
    Metric,
    NlMtu: Cardinal;
    Connected,
    SupportsWakeUpPatterns,
    SupportsNeighborDiscovery,
    SupportsRouterDiscovery: LongBool;
    ReachableTime: Cardinal;
    TransmitOffload: NL_INTERFACE_OFFLOAD_ROD;
    ReceiveOffload: NL_INTERFACE_OFFLOAD_ROD;
    DisableDefaultRoutes: LongBool;
  end;
  {$EXTERNALSYM _MIB_IPINTERFACE_ROW}
  MIB_IPINTERFACE_ROW = _MIB_IPINTERFACE_ROW;
  {$EXTERNALSYM MIB_IPINTERFACE_ROW}
  TMibIpInterfaceRow = MIB_IPINTERFACE_ROW;
  PMibIpInterfaceRow = PMIB_IPINTERFACE_ROW;

const
  iphlpapilib = 'iphlpapi.dll';

var
  HIpHlpApi: THandle = 0;
  GetIpInterfaceEntry: function(const pArpEntry: MIB_IPINTERFACE_ROW): LongInt; stdcall;
  {$EXTERNALSYM GetIpInterfaceEntry}

- / , ?

,

+3
8

Win32 BOOLEAN - , Delphi LongBool - . Delphi ByteBool.

+2

. . w2def.h, , ScopeLevelCount = 16. , 16 ,

+1
+1

, , Delphi 2, 4 8 .

TExample = record 
 f1: Integer;   // start at offset 0x00
 f2: Char;      // start at offset 0x04 
 f3: Integer;   // start at offset 0x06 or 0x08 depending on alignment
end;

TExample = packed record // this is what c++ would do
 f1: Integer;   // start at offset 0x00
 f2: Char;      // start at offset 0x04 
 f3: Integer;   // start at offset 0x05
end;
+1

ZoneIndices :

ZoneIndices : array [0..ScopeLevelCount - 1] of Cardinal;

ScopeLevelCount - , 16

+1

API/, , .

0

ULONG64 , .

, FPC , . api- .

In doubt, use some free msvc file to write sizeof (structure) and do the same under pascal. If this is consistent, and you still have doubts, calculate the field offsets using pointer magic and compare them.

0
source

Source: https://habr.com/ru/post/1710647/


All Articles