调用DLL 时,程序可以运行 ,但程序关闭后总出现错误!(100分)

H

hisman

Unregistered / Unconfirmed
GUEST, unregistred user!
library dimedll;
uses
ShareMem,
SysUtils,
Classes;
{$R *.res}
type typedime=array of string;
function zh( str:string; var sz:typedime ):integer;stdcall;
var
temp :string;
a_Stringlist :TStringList;
i:integer;
begin
try
a_Stringlist:=TStringList.Create;
temp:=str;
i:=pos('|', temp);
while i<>0 do begin
a_StringList.add(copy(temp, 1, i - 1));
temp := copy(temp, i + 1, length(temp) - i);
i:=pos('|', temp);
end;
i:=a_stringlist.Count;
setlength(sz,i);
for i:=low(sz) to high(sz) do
begin
sz:=a_stringlist.Strings;
end;
result:=1;
finally
a_stringlist.Free;
end;
end;
exports zh;
begin
end.
以上的DLL功能是输入一个串例如'ww|t|6|U|' ,用一个动态数组存储各个'|'之间的串值
我在程序中调用时,可以正常使用,但退出程序时总出现错误,错误提示如下
Project py.exe raised exception class EInvalidPointer with message
'Invalid pointer operation'.process stopped.Use Step or Run to continue

这可如何是好????????
我是在DELPHI下写的DLL ,在DELPHI 中使用尚且如此,但实际上我需用VF来调用此
DLL 库,如了解请一并告知( 急 )
 
你使用了string类型作为接口参数,所以导致出错。
如果你要是使用Delphi来调用,那么需要在调用程序中uses borlandmm,而且要放置在第一位。
看你的需求是要在VFP中调用,那么好了,你可以放弃使用String类型了,使用pChar类型代替吧。
然后注意加上stdcall,否则还会出Bug的。
 
但是我已经加了sharemem 了呀怎么还是解决不了问题???
 
将Sharemem作为第一个uses的。就是说uses后面先加sharemem,如果你在Form上加不行的话
就将它加在dpr里面,忘记是需要加在那个里面了。
还有,你使用VFP调用,这招就不行了。因为需要在调用程序里面加这个。
 
谢谢yzhshi 老兄马上给你加分!
 
接受答案了.
 
顶部