X
xie_huan
Unregistered / Unconfirmed
GUEST, unregistred user!
为什么用GetHostName(),GetHostByName()得不到中文的主机名,只会得到一串
---- 的符号?请看例子:
procedure TForm1.Button1Click(Sender: TObject);
type
TaPInAddr=array[0..10] of PInAddr;
PaPInAddr=^TaPInAddr;
var
result:string;
pheHostEnt;
pptraPInAddr;
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个 - 出现
---- 的符号?请看例子:
procedure TForm1.Button1Click(Sender: TObject);
type
TaPInAddr=array[0..10] of PInAddr;
PaPInAddr=^TaPInAddr;
var
result:string;
pheHostEnt;
pptraPInAddr;
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个 - 出现