//DLL内容
library testdll;uses
SysUtils;{$R *.res}procedure Test(p: PChar; pa : PChar);
begin
StrCat(p, 'Titttt');
StrCopy(pa,'pa');
end;
exports
Test;begin
end.
//以下部分为调用程序---------------------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementationprocedure Test(p : PChar; pa: PChar); stdcall; external 'testdll.dll';{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
var
a : array[0..254] of Char;
b : array[0..9] of Char;
begin
FillChar(a,Length(a),#0);
FillChar(b,Length(b),#0);
StrCopy(a,'123');
StrCopy(b,'000');
Test(a,b);
Text := a + b;
end;end.
在调用动态库的函数时,报地址错误,请各位帮我看一下是什么原因。另:如果只用一个参数就没有错误。
delphi
library testdll;uses
SysUtils;{$R *.res}procedure Test(p: PChar; pa : PChar);
begin
StrCat(p, 'Titttt');
StrCopy(pa,'pa');
end;
exports
Test;begin
end.
//以下部分为调用程序---------------------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementationprocedure Test(p : PChar; pa: PChar); stdcall; external 'testdll.dll';{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
var
a : array[0..254] of Char;
b : array[0..9] of Char;
begin
FillChar(a,Length(a),#0);
FillChar(b,Length(b),#0);
StrCopy(a,'123');
StrCopy(b,'000');
Test(a,b);
Text := a + b;
end;end.
在调用动态库的函数时,报地址错误,请各位帮我看一下是什么原因。另:如果只用一个参数就没有错误。
delphi
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货