1. implicit call.
Library project1;
Uses
Sysutils,
Classes;
{$ R *. Res}
Function sum (A, B: integer): integer; stdcall;
Begin
Result: = A + B;
End;
Function linkstr (str1, str2: pchar): pchar; stdcall;
Begin
Result: = pchar (strpas (str1) + strpas (str2 ));
End;
Function ifcheck (int1, int2: integer): Boolean; stdcall;
Begin
If int1> int2 then
Result: = true
Else
Result: = false;
End;
Exports
Sum, linkstr, ifcheck;
Begin
End.
========================
VaR
Form1: tform1;
Implementation
Function sum (A, B: integer): integer; stdcall; External 'project1. dll ';
Function linkstr (str1, str2: pchar): pchar; stdcall; External 'project1. dll ';
Function ifcheck (int1, int2: integer): Boolean; stdcall; External 'project1. dll ';
{$ R *. DFM}
Procedure tform1.button1click (Sender: tobject );
Begin
Self. Caption: = inttostr (sum (strtoint (edt1.text), strtoint (edt2.text )));
End;
Procedure tform1.button2click (Sender: tobject );
Begin
Self. Caption: = strpas (linkstr (pchar (edt1.text), pchar (edt2.text )));
End;
Procedure tform1.button3click (Sender: tobject );
Begin
If ifcheck (strtoint (edt1.text), strtoint (edt2.text) then
Self. Caption: = 'count 1> count 2'
Else
Self. Caption: = 'Number two is greater than number one ';
End;
End.
// Configure //------------------------------------------------------------------------------------
2. Explicit not called.
Procedure tform1.button1click (Sender: tobject );
VaR
Hdll: hmodule;
Sum: function (A, B: integer): integer; stdcall;
Begin
Hdll: = loadlibrary ('project1. dll ');
If hdll <> 0 then
Begin
@ Sum: = getprocaddress (hdll, 'sum ');
If @ sum <> nil then
Self. Caption: = inttostr (sum (strtoint (edt1.text), strtoint (edt2.text )))
Else
Showmessage ('this function does not exist in dll ');
Freelibrary (hdll );
End
Else
Showmessage ('dll cannot be loaded ');
End;
// End;
Procedure tform1.button2click (Sender: tobject );
VaR
Hdll: hmodule;
Linkstr: function (str1, str2: pchar): pchar; stdcall;
Begin
Hdll: = loadlibrary ('project1. dll ');
If hdll <> 0 then
Begin
@ Linkstr: = getprocaddress (hdll, 'linkstr ');
If @ linkstr <> nil then
Self. Caption: = strpas (linkstr (pchar (edt1.text), pchar (edt2.text )))
Else
Showmessage ('module function loading failed in dll ');
Freelibrary (hdll );
End
Else
Showmessage ('dll loading failed ');
End;
Procedure tform1.button3click (Sender: tobject );
VaR
Hdll: hmodule;
Ifcheck: function (A, B: integer): Boolean; stdcall;
Begin
Hdll: = loadlibrary ('project1. dll ');
If hdll <> 0 then
Begin
@ Ifcheck: = getprocaddress (hdll, 'ifcheck ');
If @ ifcheck <> nil then
If ifcheck (strtoint (edt1.text), strtoint (edt2.text) then
Self. Caption: = 'count 1> count 2'
Else
Self. Caption: = 'Number two is greater than number one'
Else
Showmessage ('error occurred during function loading ');
Freelibrary (hdll );
End
Else
Showmessage ('errors occurred when loading dll ');
End;
End.