function IP_Exists(IP:Pchar;Ipstrtemp:Pchar):integer; stdcall;
var
tempstr:string;
Ipstrtemp:pchar;
begintempstr := Nbt.Ipstr+'*'+ Nbt.Group + '*'+ Nbt.User + '*' + Nbt.Name + '*' + Nbt.Mac; Getmem(Ipstrtemp,length(tempstr)+1);
strPcopy(Ipstrtemp,tempstr);
FreeMem(Ipstrtemp);end;以上是dll源代码,我用外部程序调用编译好得dll后,系统无错误提示,但仅仅把
第一个‘*’前的内容传出来了!我以为是‘*’号的事,结果换了间隔符也是同样结果,请问大侠这是怎么回事,我该怎么解决?
调用的源代码为:function IP_Exists(IP:pchar; Ipstr:Pchar):integer; stdcall;external 'ipsearch.dll';procedure TForm1.Button1Click(Sender: TObject);
var
temp_ip: Pchar;
IPstr : Pchar;
begin
strPcopy(temp_ip,E_IP.text);
IP_Exists(temp_ip,IPstr); //此处调用外部函数;
if length(string(IPstr))>0 then
begin
with list_info do
begin
Items.add(string(IPstr));
end end
end;
var
tempstr:string;
Ipstrtemp:pchar;
begintempstr := Nbt.Ipstr+'*'+ Nbt.Group + '*'+ Nbt.User + '*' + Nbt.Name + '*' + Nbt.Mac; Getmem(Ipstrtemp,length(tempstr)+1);
strPcopy(Ipstrtemp,tempstr);
FreeMem(Ipstrtemp);end;以上是dll源代码,我用外部程序调用编译好得dll后,系统无错误提示,但仅仅把
第一个‘*’前的内容传出来了!我以为是‘*’号的事,结果换了间隔符也是同样结果,请问大侠这是怎么回事,我该怎么解决?
调用的源代码为:function IP_Exists(IP:pchar; Ipstr:Pchar):integer; stdcall;external 'ipsearch.dll';procedure TForm1.Button1Click(Sender: TObject);
var
temp_ip: Pchar;
IPstr : Pchar;
begin
strPcopy(temp_ip,E_IP.text);
IP_Exists(temp_ip,IPstr); //此处调用外部函数;
if length(string(IPstr))>0 then
begin
with list_info do
begin
Items.add(string(IPstr));
end end
end;
1、去掉FreeMem(Ipstrtemp);
2、函数既然不用返回值,你就不要让它返回integer型了,更何况,你现有的代码根本没有返回任何东东。
Getmem(Ipstrtemp,length(tempstr)+1);
strPcopy(Ipstrtemp,tempstr);
FreeMem(Ipstrtemp);刚刚分配内存就被销毁了啊
http://expert.csdn.net/Expert/topic/2969/2969621.xml?temp=.8635065
或者这个:
http://expert.csdn.net/Expert/topic/2960/2960622.xml?temp=.6062433
里面应该比较详细了。