DLL operation in Delphi

Use Delphi Dll Wizard to write DLL. 

 Creation: Change the DLL name when saving 

 library test2; 

 uses
SysUtils,
Classes,
forms,
dialogs; {$R *.res}
function test():string;
begin
showmessage('a');
end;
exports
test; // Need to
begin
End. Call: Function test (): string; external 'xxxxxxx \ test2.dll'; Just call the test method in button. Dynamic call DLL: Type
// Night binding, that is, dynamic calling external functions mainly use the following three commands:
// loadlibrary: Get DLL
// getProcaddress: Get function
// FreeLibrary: Release // Define a process type, the parameters should be consistent with the required functions
TMB = function(hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
mb: TMB; {Declaration function mb}
Inst: longword; {Declarier a variable to record the DLL handle to be used}
public
{ Public declarations }
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
inst := LoadLibrary('user32.dll');
if inst <> 0 then
MB := GetProcAddress(inst, 'MessageBoxW'); end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeLibrary (Inst); {Remember to release}
end;

Leave a Reply

Your email address will not be published. Required fields are marked *