I
Imfish
Unregistered / Unconfirmed
GUEST, unregistred user!
MyDll:
library MyDll;
uses
SysUtils,
Classes,
Base in 'Base.pas';
{$R *.RES}
const
MyDoubl = 'MyDoubl';
MyTripl = 'MyTripl';
exports
Doubl index 1 name MyDoubl resident ,Tripl index 2 name MyTripl resident
begin
end.
Base单元:
unit Base;
interface
function Doubl(N:integer):integer;stdcall;
function Tripl(N:integer):integer;stdcall;
implementation
uses
windows;
function Doubl(N:integer):integer;stdcall;
begin
MessageBox(0,'加倍!','MyDll',mb_ok);
Result:=N*2;
end;
function Tripl(N:integer):integer;stdcall;
begin
MessageBox(0,'三倍!','MyDll',mb_ok);
Result:=N*3;
end;
end.
调用的:
unit UDll;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Spin;
type
TDoubl = function (N:integer):integer;
TTripl = function (N:integer):integer;
TForm1 = class(TForm)
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Label1: TLabel;
Label2: TLabel;
procedure SpinEdit1Change(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//function MyDoubl(N:integer):integer;stdcall;external'mydll.dll';
//function MyTripl(N:integer):integer;stdcall;external'mydll.dll';
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.SpinEdit1Change(Sender: TObject);
var
tmpint:integer;
Moudle:THandle;
PFunc:TDoubl;
begin
Moudle:= loadlibrary('MyDll.dll');
if Moudle > 32 then
begin
PFunc:=GetProcAddress(Moudle,'MyDoubl');
tmpint:=PFunc(spinedit1.value);//就是这儿和我过不去,能出来MessageBox的对话框,但是,点了确定后就不行了出错。
label1.caption := inttostr(tmpint);
end;
Freelibrary(Moudle);
//tmpint:=MyDoubl(spinedit1.value);
//label1.Caption:=inttostr(tmpint);
end;
procedure TForm1.SpinEdit2Change(Sender: TObject);
var
tmpint:integer;
Moudle:THandle;
PFunc:TFarProc;
begin
Moudle:= loadlibrary('MyDll.dll');
if Moudle > 32 then
begin
PFunc:=GetProcAddress(Moudle,'MyTripl');
tmpint:=TTripl(PFunc)(spinedit2.value);
label2.caption := inttostr(tmpint);
end;
Freelibrary(Moudle);
//tmpint:=MyTripl(spinedit2.value);
//label2.Caption:=inttostr(tmpint);
end;
end.
library MyDll;
uses
SysUtils,
Classes,
Base in 'Base.pas';
{$R *.RES}
const
MyDoubl = 'MyDoubl';
MyTripl = 'MyTripl';
exports
Doubl index 1 name MyDoubl resident ,Tripl index 2 name MyTripl resident
begin
end.
Base单元:
unit Base;
interface
function Doubl(N:integer):integer;stdcall;
function Tripl(N:integer):integer;stdcall;
implementation
uses
windows;
function Doubl(N:integer):integer;stdcall;
begin
MessageBox(0,'加倍!','MyDll',mb_ok);
Result:=N*2;
end;
function Tripl(N:integer):integer;stdcall;
begin
MessageBox(0,'三倍!','MyDll',mb_ok);
Result:=N*3;
end;
end.
调用的:
unit UDll;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Spin;
type
TDoubl = function (N:integer):integer;
TTripl = function (N:integer):integer;
TForm1 = class(TForm)
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Label1: TLabel;
Label2: TLabel;
procedure SpinEdit1Change(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//function MyDoubl(N:integer):integer;stdcall;external'mydll.dll';
//function MyTripl(N:integer):integer;stdcall;external'mydll.dll';
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.SpinEdit1Change(Sender: TObject);
var
tmpint:integer;
Moudle:THandle;
PFunc:TDoubl;
begin
Moudle:= loadlibrary('MyDll.dll');
if Moudle > 32 then
begin
PFunc:=GetProcAddress(Moudle,'MyDoubl');
tmpint:=PFunc(spinedit1.value);//就是这儿和我过不去,能出来MessageBox的对话框,但是,点了确定后就不行了出错。
label1.caption := inttostr(tmpint);
end;
Freelibrary(Moudle);
//tmpint:=MyDoubl(spinedit1.value);
//label1.Caption:=inttostr(tmpint);
end;
procedure TForm1.SpinEdit2Change(Sender: TObject);
var
tmpint:integer;
Moudle:THandle;
PFunc:TFarProc;
begin
Moudle:= loadlibrary('MyDll.dll');
if Moudle > 32 then
begin
PFunc:=GetProcAddress(Moudle,'MyTripl');
tmpint:=TTripl(PFunc)(spinedit2.value);
label2.caption := inttostr(tmpint);
end;
Freelibrary(Moudle);
//tmpint:=MyTripl(spinedit2.value);
//label2.Caption:=inttostr(tmpint);
end;
end.