DLL- . DLL - , Delphi, .
DLL-, File|New|Other New New Item DLL Wizard.
DLL Wizard DLL-. , unit, DLL- library. uses DLL- : SysUtils Classes.
DLL- :
1. , .
2. , .
3. , , , exports.
DLL- , Delphi, , , , C++.
. , DLL- . :
register,
pascal,
cdecl,
stdcall,
safecall.
. :
function F1 (X, Y, Z: Real]: Real; stdcall;.
( ), , ( ). DLL- , , . C++ stdcall.
, DLL-, , . exports
. :
, DLL-;
, ;
.
, exports index.
, , DLL-, exports name .
|
|
DLL - . .
:
library Projectl;
uses
SysUtils, Classes;
{$R *.res}
function F1(X, Y: Integer): Integer; stdcall;
begin
F1:=X+Y;
end;
DLL-
DLL- , . DLL- .
DLL- . , DLL-, , ( DLL) DLL. DLL-, , . , , . , , , DLL-.
implementation .
external , .
"
:
unit Unitl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
Type
TForml = class(TForm)
Editl: TEdit; [ }
Edit2: TEdit; ( }
Edit3: TEdit; (
DLL-}
Buttonl: TButton; { , )
Button2: TButton; [ , }
procedure ButtonlClickfSender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
(Public declarations }
end;
var
Forml: TForml;
implementation
{$R *.dfm)
( }
function Fl (i: Integer; j:Integer): Integer; stdcall;
external 'Projectl.dll';
function F2 (i: Integer; j:Integer): Integer; stdcall;
external 'Projectl.dll index 2;
procedure TForml.ButtonlClick(Sender: TObject);
{ }
begin
Edit3.Text:=IntToStr(Fl(StrToInt(Editl.Text),StrToInt{Edit2.Text) ));
end;
procedure TForml.Button2Click(Sender: TObject);
begin
Edit3.Text:=JntToStr(F2(StrToInt(Editl.Text),StrToInt(Edit2.Text)));
end;
end.
DLL-
DLL-, , DLL- . DLL- . DLL- . DLL- Windows API. Windows API - , .
DLL- external , , .
|
|
DLL-, :
1. . ( type).
:
TMyFl=function(i,j:Integer):Integer; stdcall;
2. var interface- . : MyFl: TMyFl;
3. DLL- Integer, .
4. LoadLibrary, DLL-. ; h:=LoadLibrary ('Projectl.dll');
5. , . DLL- , LoadLibrary 0.
6. DLL- . Windows API GetProcAddress, DLL- . : @MyFl: =GetProcAddress (h, ' Fl ');
7. , ( @MyFl) nil.
8. DLL-.
9. DLL- FreeLibrary, DLL-.
:
unit Unitl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
type
TForml = class(TForm)
iditl: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button3: TButton;
procedure Button3Click[Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyFl=function(i,j:Integer):Integer; stdcall; {
)
var
Forml: TForml;
MyFl: TMyFl; ( ]
implementation
{$R *.dfm}
procedure TForml.Button3Click(Sender: TObject);
var
h: Integer;
begin
h:=LoadLibrary('Projectl.dll');
if h <> 0 then
begin
@MyFl:=GetProcAddress(h,'Fl');
if @MyFl <> nil then
Edit3.Text:=IntToStr(MyFl(StrToInt{Editl.Text),
StrToInt(Edit2.Text)));
FreeLibrary(h);
end;
end;
end.
DLL- .
DLL- . , , . Close .
Create, - . DLL-.
DLL-, , .
:
library Projectl;
uses
SysUtils,
Classes,
Unitl_DLL in 'Unitl_DLL.pas' {Forml};
{$R '.res}
procedure MyModalForm (var Z:Integer;F:TForm1); stdcall;
begin
Form1:=TForml.Create(F);
( F
- }
Form1.ShowModal();
( }
Z:=StrToInt(Form1.Edit1.Text);
Form1.Free;
end;
exports MyModalForm;
end.
DLL- , , .
DLL-, .
:
|
|
unit Unitl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, StdCtris;
type
TForml = class(TForml
Button4: TButton;
Edit4: TEdit;
procedure Button4Click(Sender: TObject);
private
public
end;
TMyModalFora=procedure(var Z:Integer; F:TForml); stdcall;
var
Forml: TForml;
MyModalForm: TMyHodalForm; (
]
implementation
{$R *.dfml
procedure TForml.Button4Click(Sender: TObject);
var
244 6
h: Integer;
ii: Integer; { )
begin
ii:=0;
h:=LoadLibrary('Projectl.dll'};
if h 0 then
begin
@MyModalForm:=GetProcAddress(h,'HyModalForm');
if @MyModalForm nil then
MyModalForm(ii,Forml);
FreeLibrary(h);
end;
Edit4.Text;= IntToStr(ii); { ,
MyModalForm DLL-)
end;
end.