Home > Back-end >  Little confused about create DLL file
Little confused about create DLL file

Time:09-29

The following public unit use on the DLL project exactly? If it is, when the build is also on the DLL file? To use this DLL program also USES the public unit, is to copy a common element in the development of the program directory? So there is a DLL, the program of a folder, and two public unit file,,,, so do you,,,,
Screenshots are as follows:

The code is as follows:
With Delphi wrapper class to DLL:

A common unit:
 
The unit ITest;

Interface

Type
IT=interface
The function get string: a string;
Procedure ShowMsg (p: PChar);
Procedure of Msg.
end;

Implementation

End.


Class unit, the write inside the DLL:
 unit UTest; 

Interface

USES the
SysUtils,
Windows,
ITest;

Type
TTest=class (TInterfacedObject, IT)
Private
I: Integer;
Protected

Public
The constructor Create;//override.
The destructor Destroy; Override.
The function get string: a string;
Procedure ShowMsg (p: PChar);
Procedure of Msg.
Published

end;

Implementation

The constructor TTest. Create;
The begin
I:=0;
end;

Destructor TTest. Destroy;
The begin
Inherited;
end;

The function TTest. Get string: a string;
The begin
Result:='Test string';
end;

Procedure TTest. ShowMsg (p: PChar);
The begin
MessageBox (0, p, "Test", MB_OK);
end;

Procedure TTest. Msg;
The begin
Inc (I);
MessageBox (0, 'Test MessageBox', PChar (IntToStr (I)), MB_OK);
end;

End.


DLL PRJ:
 library Test; 

USES the
SysUtils,
Classes,
ITest in 'ITest. Pas,
UTest 'in UTest. Pas';

{$R *. Res}

The function TestCreate: IT; Stdcall;
The begin
Result:=TTest. Create;
end;

Exports
TestCreate;//use the initialization

The begin
End.


DLL part that's it, calls to EXE parts:

 USES 
ITest;//reference units

The function TestCreate: IT; Stdcall; External 'Test. DLL' name 'TestCreate';//reference DLL function

//declare as test
Private
AA: IT;
BB: IT;

Procedure TForm1. FormCreate (Sender: TObject);
The begin
AA:=TestCreate;
BB:=TestCreate;
end;

Procedure TForm1. Button1Click (Sender: TObject);
The begin
For the Caption:=AA. Get string;
end;

Procedure TForm1. Button2Click (Sender: TObject);
The begin
AA. ShowMsg (' 123 ABC ");
end;

Procedure TForm1. Button3Click (Sender: TObject);
The begin
AA. Msg;
end;

Procedure TForm1. Button4Click (Sender: TObject);
The begin
BB. Msg;
end;


CodePudding user response:

Should have, put a DLL and procedures,

CodePudding user response:

DLLS are not Shared communication parameters, free will, of course, the
But a better approach is to solve the Shared parameters, so you don't put,
  • Related