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, theBut a better approach is to solve the Shared parameters, so you don't put,