DLL file creation and calls in Delphi

zhaozj2021-02-17  55

Topic: DLL file creation and calls in Delphi

At present, the development of the system is in a combination of several people, and the workhe way is developed, which is also convenient for the rapid development of the system. The DLL method is most convenient. I have now organized some information, I hope to help some students needed (remember when I am studying, ask people to teach an unimaginable thing). // (Copy Source Book)

I. Writing of the function process:

Library firstdll;

Uses sysutils, classes;

{$ R * .res} // 1. Define function specific procedures and output interface mode / / --------------------------- --- // Function 1 // Function: Things Data 3 times amplified function // ----------------------------- -function bbntossnn (SourceResult: Integer): Integer; stdcall; begin if sourceResult> 0 Then Result: = sourceReSult 3 / / The result is stored in the Result else result: = sourceRereSult; End;

Exports bbntossnn; // 2. Function output definition end.

====

II. Create form ============================================================================================================================== 1. Step by step, create a DLL project

Library mgrpersn; Uses sysutils, classes, mgrperfm in 'mgrperfm.pas' {formperson}; // 1.form code (like a general Form)

{$ R * .res} exports showpersn; // 2. Function output definition beginend.

2. Setting the FORM set in the DLL ========================================= === Unit mgrperfm;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Comctrls, Toolwin, Imglist;

Type TFormPerson = Class (TForm) private {private declarations} public {public declarations}

// The variables of some are no longer used, to change a place, as follows (one of the changes) // var // FormPerson: TFormPerson;

{Declare FORM function exit} // changed two funpePersn (Ahandle: Thandle; Acaption: String): bool; stdcall;

IMPLEMENTATION

{$ R * .dfm} // letter Data Process Definition Function ShowPersn (Ahandle: Thandle; Acaption: String): Bool; Var formPerson: TFormPerson; // Define Form (above) Begin // Copy Application handle to the DLL should have an article object Application.Handle: = aHandle; FormPerson: = TFORMPERSON.CREATE (Application); // Creating a control TFORM try formon.caption: = acAption; FormPerson.showModal; // Show this Form Result : = False; // Reversal success value Finally formPerson.free; end; end; three.DLL functions and form call ====================== ===== 1. Call method one ------------- Implementation // The following write DLL DLL

{$ R * .dfm} // DLL internal function call function bbntossnn (SourceResult: Integer): integer; stdcall external 'firstdll.dll';

........

2. Call method two ============== Type / / Create a function class here // 1 ------------------- ------------ TshowPersn = Function (Ahandle: Thandle; Acaption: String): Bool; stdcall; edlloaderror = class (exception); // Create an error record class // 1 ----------------------------- TMAINCLTR = Class (TFORM) // The system is unchanged, the system is automatically generated

......

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

New Post(0)