You don't want to convert from PAnsiChar
to PWideChar
. On your Unicode Delphi your PChar
maps to PWideChar
. But gethostbyname
receives PAnsiChar
. You need to convert from Unicode to ANSI.
Code it like this:
phe := gethostbyname(PAnsiChar(AnsiString(AIP)));
In other words, convert your string to AnsiString
, and then cast as PAnsiChar
. Personally I'd declare the AIP
parameter to be AnsiString
.
procedure TranslateStringToTInAddr(const AIP: AnsiString; var AInAddr);
And then write the call to gethostbyname
like so:
phe := gethostbyname(PAnsiChar(AIP));
That untyped var
parameter looks dubious to me. I see no compelling reason for its use. What's wrong with declaring it to be of type TIPAddr
? Your FillChar
is somewhat dubious. How can you use SizeOf
on an untyped parameter?