delphi - What is this code doing with pointers? -


I still do not understand how the indicators work in Delphi while reviewing a library, in one function I Generally, I used the GetIPAddress (used to get the IP address of the local machine), I used the pointers (the marked line below) near a strange artist. I did not write it, but found it sometime ...

  uses Winsock; Function GetIPAddress: String; Type pu_long = ^ u_long; Var varTWSAData: TWSAData; VarPHostEnt: Fistent; VarTInAddr: TInAddr; Namebook: Array [0 .. 255] Anikar; If WSAStartup ($ 101, varTWSAData) & lt; & Gt; 0 Then the result: = '' and get started hostname (Nambuf, Sagef (nominator)); VarPHostEnt: = gethostbyname (namebuf); VarTInAddr.S_addr: = u_long (pu long (varPHostEnt ^. H_addr_list ^) ^); // & lt; --- ??? Result: = WideString (inet_ntoa (varTInAddr)); End; Excluding the result: = ''; End; Finally WSACleanup; End; End;   

What's going on here with the pointer?

fastend is an indicator for one, in a type defined Windows API . H_addr_list is an array of parasitic values ​​which is actually an array of bytes (C, one four and one byte is the same thing, which is complicated in handling C API byte buffers).

What is this saying: / P>

  • varPHostEnt ^: Denture the pointers to host
  • h_addr_list ^ Get the first member
  • Pu_long cast: Explain the first member (a byte array pointer) as an inverted indicator
  • pu_long () ^: To reprint this pointer and restore it Inverted:
  • Reversal: Unnecessary, as we are already working with a vault.
  • S_addr: = in_addr record one While the type that can be defined as an array of a UIT 32 (4-byte unsigned integer) or 4 individual bytes. Assign this Ulound (4-byte unsigned integer) to pre-interpretation.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -