X
xie_huan
Unregistered / Unconfirmed
GUEST, unregistred user!
在WIn98+delphi 6下,用GetHostName(),GetHostByName()得不到中文的主机名,只会得到一串
---- 的符号?请看例子:
procedure TForm1.Button1Click(Sender: TObject);
type
TaPInAddr=array[0..10] of PInAddr;
PaPInAddr=^TaPInAddr;
var
result:string;
phe
HostEnt;
pptr
aPInAddr;
Buffer:array[0..63] of char;
I:Integer;
GinitData:TWSADATA;
begin
WSAStartUp($101,GinitData);
result:='';
GetHostName(Buffer,SizeOf(Buffer));
phe:=GetHostByName(Buffer);
if phe=nil then exit;
pptr:=PaPInAddr(phe^.h_addr_list);
i:=0;
while pptr^<>nil do
begin
result:=StrPas(inet_ntoa(pptr^^));
inc(i);
end;
WSACleanup;
edit1.text:=result;
edit2.Text:=phe.h_name;
end;
有n个中文字符,就有2n个 - 出现,加上 result := WideString(StrPas(inet_ntoa(pptr^^)))也不行
---- 的符号?请看例子:
procedure TForm1.Button1Click(Sender: TObject);
type
TaPInAddr=array[0..10] of PInAddr;
PaPInAddr=^TaPInAddr;
var
result:string;
phe
![Stick Out Tongue :P :P](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
pptr
![Stick Out Tongue :P :P](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
Buffer:array[0..63] of char;
I:Integer;
GinitData:TWSADATA;
begin
WSAStartUp($101,GinitData);
result:='';
GetHostName(Buffer,SizeOf(Buffer));
phe:=GetHostByName(Buffer);
if phe=nil then exit;
pptr:=PaPInAddr(phe^.h_addr_list);
i:=0;
while pptr^<>nil do
begin
result:=StrPas(inet_ntoa(pptr^^));
inc(i);
end;
WSACleanup;
edit1.text:=result;
edit2.Text:=phe.h_name;
end;
有n个中文字符,就有2n个 - 出现,加上 result := WideString(StrPas(inet_ntoa(pptr^^)))也不行