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

History:

Translation of IP_OPTION_INFORMATION32 and ICMP_ECHO_REPLY32 structures for a 64-bit compiler. I am stuck with using data types. Definitions of structures from a link:

Structure IP_OPTION_INFORMATION32:

 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 path (for Delphi XE2, 64-bit target platform). As you can see, I do not 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 a 64-bit target platform Delphi XE2 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 do you define the types UCHAR * POINTER_32 and VOID * POINTER_32 in Delphi for the target platform of a 64-bit platform? As far as I know, a 32-bit pointer type is available for the target platform of a 64-bit platform, and I just don’t like that it is defined, for example. as type Int32

What is the most accurate translation for these types?

+4
source share
2 answers

The question is what POINTER_32 considered in another question: POINTER_32 - what is it and why?

You would use it when interacting with structures that are defined in another process, with 32-bit pointers.

You don't have the __ptr32 equivalent in Delphi, so you have no choice but to declare it as a 32-bit integer. I would use the unsigned type.

+4
source

In this case, UInt32 (or Cardinal, DWORD, etc. - all unsigned 32 bits) will be fine. All you have to do is declare a 32-bit unsigned character with the correct position of the structure (record). The CPU wouldn’t care, the compiler wouldn’t care (you can give a type when specified if necessary), is it really a pointer or not. Even a signed 32-bit will work if you don't do some math with checking values ​​and checking processor flags. And one more thing in the translation structure from C to Delphi: make sure that the original alignment was 4 bytes (32 bits per element), because record in contrast to packed record (without alignment) by default using the same alignment of 4 bytes. In addition, you may have problems applying your records to data like

 type Picmp_echo_reply32 = ^icmp_echo_reply32; ... data_size := Picmp_echo_reply32(@mybuf[some_offset]).DataSize; 

or

 var icmp_echo: Picmp_echo_reply32; ... icmp_echo := @buf[offset]; reserved := icmp_echo.Reserved; 
0
source

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


All Articles