T
tigerhacker
Unregistered / Unconfirmed
GUEST, unregistred user!
下面这个是我写的动态链接库文件,功能是传入两个任意位数的整数,输出结果为两个数的和,我把生成的动态链接库放在我的主程序目录下,然后在我的主程序里面调用这个动态链接库,语句是:
function addab(num1,num2:string):string;stdcall;external 'project2.dll';
showmessage(addab('123','11111'));
输出结果正确,可是出现错误提示框说"非法的指针操作",请大家帮忙研究下!谢谢
library Project2;
uses
SysUtils,
Classes;
const n=100;
type arrtype=array[1..n] of byte;
{$R *.res}
function addab(num1,num2:string):string;stdcall;
var
a,b:arrtype;
i:integer;
shuchu:string;
T,s:byte;
begin
for i:=1 to ndo
begin
a:=0;
b:=0;
end;
for i:=1 to length(num1)do
a[n+1-i]:=ord(num1[length(num1)+1-i])-48;
for i:=1 to length(num2)do
b[n+1-i]:=ord(num2[length(num2)+1-i])-48;
T:=0;
for i:=ndo
wnto 1do
begin
s:=a+b+T;
a:=s mod 10;
t:=s div 10;
end;
i:=1;
while (a=0) and (i<n)do
inc(i);
shuchu:='';
while i<=ndo
begin
shuchu:=shuchu+inttostr(a);
inc(i);
end;
Result:=shuchu;
end;
exports //引出函数名
addab;
end.
function addab(num1,num2:string):string;stdcall;external 'project2.dll';
showmessage(addab('123','11111'));
输出结果正确,可是出现错误提示框说"非法的指针操作",请大家帮忙研究下!谢谢
library Project2;
uses
SysUtils,
Classes;
const n=100;
type arrtype=array[1..n] of byte;
{$R *.res}
function addab(num1,num2:string):string;stdcall;
var
a,b:arrtype;
i:integer;
shuchu:string;
T,s:byte;
begin
for i:=1 to ndo
begin
a:=0;
b:=0;
end;
for i:=1 to length(num1)do
a[n+1-i]:=ord(num1[length(num1)+1-i])-48;
for i:=1 to length(num2)do
b[n+1-i]:=ord(num2[length(num2)+1-i])-48;
T:=0;
for i:=ndo
wnto 1do
begin
s:=a+b+T;
a:=s mod 10;
t:=s div 10;
end;
i:=1;
while (a=0) and (i<n)do
inc(i);
shuchu:='';
while i<=ndo
begin
shuchu:=shuchu+inttostr(a);
inc(i);
end;
Result:=shuchu;
end;
exports //引出函数名
addab;
end.