Plugin Management Frame for Delphi (3)

zhaozj2021-02-11  175

1 Introduction

2 plug-in frame (unddllmanager)

3 Example of use

3.1 class diagram

3.2 client components

Derived Tclientdll from TDLL;

Add related properties according to the real dynamic library interface;

3.2.1 Component Definition

Unit unclientdll;

Interface

Uses

Windows, classes, sysutils, unddllmanager, unprocdefine;

Type

EclientDLLLEROR = Class (Exception);

{Tclientdll

o inherits from TDLL;

o Automatically get the ClientInitialize address and save it in the ClientInitialize property;

o Automatically get the ClientInsertTrigger address and save it in the ClientInsertTrigger property;

}

Tclientdll = Class (TDLL)

Private

FclientInitialize: TclientInitialize;

FclientInsertTrigger: TclientInsertTrigger;

Fclientgetdescription: Tclientgetdescription;

FclientSetup: TclientSetup;

FDESCRIPTION: STRING;

Fusetrigger: BOOL;

protected

Procedure Dodlloaded; Override;

Procedure Dodllunloaded; Override;

public

CONSTRUCTOR CRETE; OVERRIDE;

Property ClientGetDescription: Tclientgetdescription Read Fclientgetdescription

Property ClientInitialize: TclientInitialize Read FclientInitialize;

Property ClientInsertTrigger: TclientInsertTrigger Read FclientInsertTrigger;

Property ClientSetup: TclientSetup Read FclientSetUp;

Property Description: String Read FDESCRIPTION WRITE FDESCRIPTION;

Property userigger: BOOL Readrigger Write FuseTrigger;

END;

IMPLEMentation

{Tclientdll}

Constructor tclientdll.create;

Begin

inherited;

FclientInitialize: = NIL;

FclientInsertTrigger: = nil;

Fclientgetdescription: = nil;

FclientSetup: = NIL;

END;

Procedure tclientdll.dodllloaded;

Begin

FclientInitialize: = getProcadDress (csclientInitialize);

IF not assigned (fclientInitialize) THEN

Raise EclientdllerRor.create ('No Found of Proc "ClientInitialize";);

FclientInsertTrigger: = getProcadDress (csclientInsertTrigger); if not assigned (fclientInserttrigger)

Raise Eclientdller.create ('No Found of Proc "ClientInsertTrigger";);

// Optional interface, even if there is no existence.

Fclientgetdescription: = getProcaddress (csclientgetdescription);

FclientSetup: = getProcadDress (CSClientSetup);

inherited;

END;

Procedure Tclientdll.dodllunloaded;

Begin

inherited;

FclientInitialize: = NIL;

FclientInsertTrigger: = nil;

Fclientgetdescription: = nil;

FclientSetup: = NIL;

END;

End.

3.2.2 Use of components

Procedure TXXXSERVER.LOADCLIENTDLL (Const filename: string);

// Features: Load a clientdll and pass the relevant data into

VAR

Index: Integer;

Description: String;

Usetrigger: bool;

Aclientdll: Tclientdll;

Begin

INDEX: = fclientdlls.add (filename);

IF Index <0 THEN

Raise ExxxError.createfmt ('clientdll "% s" is already loaded.', [filename]);

/ / Try to read the address

Try

Fclientdlls [index] .loaded: = true;

Finally

IF not fclientdlls [index] .loaded then

Fclientdlls [index] .free;

END;

// Initialize the Client while incoming related information

Usetrigger: = false;

Aclientdll: = Tclientdll (fclientdlls [index]);

IF assigned (aclientdll.clientsetup) THEN

Aclientdll.ClientSetup (MscappPath 'Client /', False);

END;

3.3 server components

3.3.1 Component Definition

Unit unserverdll;

Interface

Uses

Windows, classes, sysutils, unddllmanager, unprocdefine;

Type

Eserverdller = Class (Exception);

{TSERVERDLL

o inherits from TDLL;

o Automatically get QueryInterface address and save it in the queryinterface property;

}

TSERVERDLL = Class (TDLL)

Private

Ffunctions: TOBJECT;

FQUERYINTERFACE: TPROCQUERYINTERFACE;

protected

Procedure Dodlloaded; Override;

Procedure Dodllunloaded; Override;

public

Procedure refreshallfunctionsPermit; Property functions: TOBJECT Read ffunctions Write FFunctions

Property Queryinterface: TPROCQUERYINTERFACE: TPROCQUERYINTERFACE r

END;

IMPLEMENTATION

Uses

UNTFunctionProc;

{TSERVERDLL}

Procedure TSerVerdll.dodllloaded;

Begin

FQueryInterface: = getProcaddress (csqueryinterface);

IF not assigned (FQueryinterface) THEN

Raise eserverdller.create ('no found of "queryinterface" proc.');

Inherited; // This sentence needs to be placed behind

END;

Procedure tServerdll.dodllunloaded;

Begin

inherited;

FQUERYINTERFACE: = NIL;

END;

Procedure TServerdll.refreshallfunctionsPermit;

VAR

I: integer;

Begin

ASSERT (FFunctions <> NIL);

For i: = 0 to tfunctionList (ffunctions) .count - 1 do

IF TFunction (TFunctionList (ffunctions) [i]). DLL = SELF THEN

TFunction (TFunctionList (ffunctions) [i]). Permit: = permit;

END;

End.

3.3.2 Component

slightly.

Culture

转载请注明原文地址:https://www.9cbs.com/read-5302.html

New Post(0)