有关dll的一个问题?
我用dll文件调用一个可视窗体,但是运行后老是报错:
access violation at address... in module "password.dll" write of
address...
请问是怎么回事?
各个模块的代码如下:
library mydll;
uses
SysUtils,
frm_call_dll,
Classes;
{$R *.res}
exports
area,volume;
begin
end.
unit frm_call_dll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
function area(R: integer): integer; stdcall; export;
function volume(R: integer): integer; stdcall; export;
type
Tfrm_call = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
//const pi = 3;
var
frm_call: Tfrm_call;
implementation
function area(R: integer): integer; stdcall; export;
begin
result := R*R;
end;
function volume(R: integer): integer; stdcall; export;
begin
result := R*R*R;
end;
{$R *.dfm}
end.
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
function area(R: integer): integer;
function volume(R: integer): integer;
type
Tfrm_main = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_main: Tfrm_main;
implementation
function area(R: integer): integer; external 'mydll.dll' name 'area';
function volume(R: integer): integer; external 'mydll.dll' name 'volume';
{$R *.dfm}
procedure Tfrm_main.Button1Click(Sender: TObject);
begin
showmessage('开始计算');
label4.Caption := inttostr(area(strtoint(edit1.Text)));
label5.Caption := inttostr(volume(strtoint(edit1.Text)));
end;
end.