Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
687 views
in Technique[技术] by (71.8m points)

winapi - How to define "UCHAR * POINTER_32" and "VOID * POINTER_32" types in Delphi?

Background:

Translating the IP_OPTION_INFORMATION32 and ICMP_ECHO_REPLY32 structures for 64-bit compiler I got stucked with data types to use there. Structure definitions from the reference:

The IP_OPTION_INFORMATION32 structure:

typedef struct _IP_OPTION_INFORMATION32 {
  UCHAR              Ttl;
  UCHAR              Tos;
  UCHAR              Flags;
  UCHAR              OptionsSize;
  UCHAR * POINTER_32 OptionsData;
} IP_OPTION_INFORMATION32, *PIP_OPTION_INFORMATION32;

I would translate this way (for Delphi XE2, 64-bit target platform). As you can see, I don't know what type to use for the OptionsData field of the structure:

IP_OPTION_INFORMATION32 = record
  Ttl: UCHAR;
  Tos: UCHAR;
  Flags: UCHAR;
  OptionsSize: UCHAR;
  OptionsData:       // what should I use here for UCHAR * POINTER_32 ?
end;

ICMP_ECHO_REPLY32 structure:

typedef struct icmp_echo_reply32 {
  IPAddr                         Address;
  ULONG                          Status;
  ULONG                          RoundTripTime;
  USHORT                         DataSize;
  USHORT                         Reserved;
  VOID * POINTER_32              Data;
  struct ip_option_information32  Options;
} ICMP_ECHO_REPLY32, *PICMP_ECHO_REPLY32;

For Delphi XE2 64-bit target platform I would write:

ICMP_ECHO_REPLY32 = record
  Address: TIPAddr;  // defined before
  Status: ULONG;
  RoundTripTime: ULONG;
  DataSize: USHORT;
  Reserved: USHORT;
  Data:              // what should I use here for VOID * POINTER_32 ?
  Options: IP_OPTION_INFORMATION32;
end;

Question:

How would you define the UCHAR * POINTER_32 and VOID * POINTER_32 types in Delphi for 64-bit platform target ? As far as I know, there is no 32-bit pointer type available for 64-bit platform target and I just don't like it to be defined e.g. as a Int32 type :-)

What is the most precise translation for the mentioned types ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The issue of what POINTER_32 is covered in another Stack Overflow question: POINTER_32 - what is it, and why?

You would use it when performing interop with structs that are defined in a different process, one that has 32 bit pointers.

You don't have the equivalent of __ptr32 in Delphi so you have simply no choice other than to declare it as a 32 bit integer. I would use an unsigned type.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...