因为可以TTcpClient的LocalHostAddr和LocalHostName来获得的本地的机器名和IP,我想把这写在一个DLL内。如下unit NetFun;interfaceuses
Sockets;
function GetLocalPCName : string; stdcall;
function GetLocalPCIP : string; stdcall;implementationfunction GetLocalPCName : string; stdcall;
var tmpV : TTcpClient;
begin
tmpV := nil;
try
tmpV := TTcpClient.Create(Application);
result := tmpV.LocalHostName;
finally
tmpV.Free;
end;
end;function GetLocalPCIP : string; stdcall;
var tmpV : TTcpClient;
begin
tmpV := nil;
try
tmpV := TTcpClient.Create(Application);
result := tmpV.LocalHostAddr;
finally
tmpV.Free;
end;
end;end.
我在外部的EXE调用这个函数的时候,可以有正确的返回值,但马上报“无效的指针操作”。我不知道这是为什么,请各位高手指教。一定给分。
Sockets;
function GetLocalPCName : string; stdcall;
function GetLocalPCIP : string; stdcall;implementationfunction GetLocalPCName : string; stdcall;
var tmpV : TTcpClient;
begin
tmpV := nil;
try
tmpV := TTcpClient.Create(Application);
result := tmpV.LocalHostName;
finally
tmpV.Free;
end;
end;function GetLocalPCIP : string; stdcall;
var tmpV : TTcpClient;
begin
tmpV := nil;
try
tmpV := TTcpClient.Create(Application);
result := tmpV.LocalHostAddr;
finally
tmpV.Free;
end;
end;end.
我在外部的EXE调用这个函数的时候,可以有正确的返回值,但马上报“无效的指针操作”。我不知道这是为什么,请各位高手指教。一定给分。
var tmpV : TTcpClient;
begin
tmpV := nil;
try
tmpV := TTcpClient.Create(Application);
showmessage('test');
result := tmpV.LocalHostAddr;
finally
tmpV.Free;
end;
end;
如果还有问题,将函数返回值改为pchar。
不使用bpl时,string不能在参数中传递,能否作为返回值,我就不太记得了。
试一试。