我的DLL事例哪里错了? delphi
一执行程序就死掉了,是哪里出问题了?
这是dll里面的代码
unit Unit1;
interface
uses
Windows, SysUtils, Classes, ADODB, WinSock;
function iff(a: Integer):Integer;stdcall;
implementation
function iff(a: Integer): Integer; stdcall;
begin
if a > 0 then
Result := 1111;
end;
end.
这是调用代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls,Unit2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
q:Integer;
begin
q:=iff(3,5);
ShowMessage(IntToStr(q));
end;
end.
我先生成dll文件,再把dll文件拷贝到调用代码的目录下
可是一运行程序,就死了,这是为什么啊,哪里出错了?
答案:dll:
unit Unit1;
interface
uses
Windows, SysUtils, Classes, ADODB, WinSock;
// function iff(a: Integer):Integer;stdcall;
implementation
function iff(a: Integer): Integer; stdcall;
begin
if a > 0 then
Result := 1111;
end;
exports
iff;
end.
exe:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls,Unit2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function iff: Integer;stdcall;external 'XXXX.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
q:Integer;
begin
q:=iff(3,5);
ShowMessage(IntToStr(q));
end;
end.好
上一个:delphi 如果网页打开失败则程序暂停
下一个:delphi怎样读取ini里的热键配置?