第一次编DLL文件,编译通过,但运行时出现如下提示:
access violation at 0x00000000 address:read of addresss 0x00000000.process
stoped.use step or run to continue.
源程序如下,Project1.dll和调用工程Project12.dpr是放在同一目录下。
library Project1;uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas';exports
addexam;{$R *.res}begin
end.
////////////////////////////////////////////////////
unit Unit1;
interface
function addexam(a:integer;b:integer):integer;export;implementationfunction addexam(a:integer;b:integer):integer;
var
c:integer;
begin
c:=a+b;
result:=c;
end;
end./////////////////////////////////////////////////////////////
unit Unit12;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;function addexam(a:integer;b:integer):integer;stdcall;external'Project1.dll';implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
d,e,f:integer;
begin
d:=1;
e:=3;
f:=addexam(d,e);
label1.Caption:=inttostr(f);
end;end.
access violation at 0x00000000 address:read of addresss 0x00000000.process
stoped.use step or run to continue.
源程序如下,Project1.dll和调用工程Project12.dpr是放在同一目录下。
library Project1;uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas';exports
addexam;{$R *.res}begin
end.
////////////////////////////////////////////////////
unit Unit1;
interface
function addexam(a:integer;b:integer):integer;export;implementationfunction addexam(a:integer;b:integer):integer;
var
c:integer;
begin
c:=a+b;
result:=c;
end;
end./////////////////////////////////////////////////////////////
unit Unit12;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;function addexam(a:integer;b:integer):integer;stdcall;external'Project1.dll';implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
d,e,f:integer;
begin
d:=1;
e:=3;
f:=addexam(d,e);
label1.Caption:=inttostr(f);
end;end.
unit Unit1;
interface
function addexam(a:integer;b:integer):integer;stdcall;export; //加上“stdcall”指示,两边的声明要一样~~implementationfunction addexam(a:integer;b:integer):integer;
var
c:integer;
begin
c:=a+b;
result:=c;
end;
end./////////////////////////////////////////////////////////////