Call the FORM in the DLL file

xiaoxiao2021-03-06  93

Call the FORM in the DLL file

Author: e Meng Yuan

I have been published in a post! ! !

Call the FORM in the DLL file, the specific implementation process is as follows:

Library Project1;

Uses

SYSUTILS,

Classes, Forms, Windows, Dialogs,

Unit1 in 'unit1.pas' {form1};

{$ R * .res}

Function showform (Formname: string): boolean; stdcall;

VAR

THECLASS: TPERSISTENTCLASS;

AFORM: TFORM;

Begin

Result: = FALSE;

{There are many forms in your DLL, please register here.

RegisterClasses ([TFORM1, TFORM2, TFORM3, ...];

}

RegisterClasses ([TFORM1]);

Theclass: = GetClass ('T' FormName);

IF (theclass = NIL) THEN EXIT;

If theclass.inheritsfrom (tform) THEN

Begin

AFORM: = TFORM (THECLASS.CREATE) .CREATE (NIL);

Try

AFORM.SHOWMODAL;

RESULT: = TRUE;

Finally

Freeandnil (AFORM);

END;

END;

END;

Exports

SHOWForm;

Begin

End.

....

Procedure Rundllform (Const DllFileName: String; const methodname: string);

Type

Trunform = function (Formname: string): boolean; stdcall;

VAR

Runform: trunform;

Getdllhwnd: hwnd;

Begin

GetdllhWnd: = loadingLibrary (Pchar (DLLFileName);

Try

IF getdllhwnd <32 THEN

Begin

Messagebox (0, PCHAR ('Didn't find' DLLFileName 'DLL file!'), 'Loading DLL failed', MB_OK);

EXIT;

END;

@Runform: = getProcaddress (getdllhwnd, pchar (methodname);

IF @runform <> nil kil

Try

Runform (DLLFormName);

Except

Raise Exception.create ('Sorry, I can't find T' DLLFORMNAME 'form!');

end

Else

Raise Exception.create ('invalid method name call');

Finally

Freelibrary (getDLLHWND);

END;

END;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

RundllForm ('Project1.dll', 'Form1', 'ShowForm');

END;

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

New Post(0)