Menu
Is free
registration
home  /  Multimedia/ Dynamic libraries dll delphi examples. Creating a DLL

Dynamic libraries dll delphi examples. Creating a DLL

DLL- Dynamic Link Library otherwise dynamic link library, which allows you to reuse the same functions in different programs. It's actually quite a handy tool, especially since once written a library can be used in many programs. In today's lesson we will learn how to work with dll And of course create them!
Well, let's start!

Let's start by creating our first Dynamic Link Library! Let's go to Delphi and immediately climb into the menu File -> New -> Other.
The following window appears before us:

Select Dynamic-Link Library from the list (in versions prior to 2009 Delphi item is called DLL Wizard).

As a result, we only have a window with the code, notice we don’t have any form here!
Now the fun begins. Let's write our first procedures in the library.

library Project2;
//You probably already noticed that instead of program
//when creating a dll, the word library is used.
// Signifier library.
uses
Sysutils, dialogs,
classes; // Attention! Don't forget to include these modules,
// otherwise the code will not work

($R*.res)
(THIS PART WILL PUT THE DLL CODE)

First ProcedureCall; stdcall; export;
//Stdcall - This statement pushes the parameters onto the stack
//right to left, and aligned to standard value
//Export, in principle, can be omitted, used for clarification
//export procedure or function.

Begin
ShowMessage(" My first procedure in dll");

end;

DoubleProcedureCall; stdcall; export;
Begin
ShowMessage(" My second procedure");
// Call the message to the screen
end;

Exports FirstCall, DoubleCall;
//Exports contains a list of exported items.
//Which will later be imported by some program.

begin
end.

This is where we will stop for now. for a simple example, this will be sufficient. Now we save our project, I personally saved it under the name Project2.dll and press the key combination CTRL + F9 to compile the library. In the folder where you saved the dpr file, a file with the dll extension must appear, this is our newly created library. I have it called Project2.dll

Let's now deal with calling procedures from this library. We create a new application according to the standard scheme. Before us is nothing unusual, just a form. We save the new application in some folder. And in the same folder we copy the newly created dll library. Those. in this example Project2.dll

Now you have to choose how to call the functions from the library. There are two call methods in total.

Method number 1
Perhaps this is the simplest method of calling procedures in the library.
Ideal for working with only one library.

Here we go...
After the implementation keyword, write the following code:

First ProcedureCall; stdcall; external "Project2.dll" ;
// Project2.dll can be any library name instead

DoubleProcedureCall; stdcall; external "Project2.dll" ;

Here, as you may have guessed, we tell the program the names of our procedures and say that they are in dll library, in my case named Project2.dll

Now, in order to call these procedures, we only need to insert their names anywhere in the code, which we will do now. We throw 2 Button components on the form from the Standard tab and create an OnClick event handler on each

OnClick of the first button:


Begin
first call;
end;

OnClick of the second button:


Begin
double call; // The name of the procedure that is in the dll
end;

That's all!

Method number 2:
More complicated than the first one, but it has its advantages, and most importantly, it is ideal for plugins.
To use this method, we first declare a few global variables:

Var
LibHandle: HModule; //Link to the library module
FirstCall: procedure; stdcall;
//Names of our procedures in the library.

DoubleCall: procedure; stdcall;

Then, after the implementation keyword, we write a procedure that will load our library:

Load ProcedureMyLibrary(FileName: String);
Begin
LibHandle:= LoadLibrary(PWideChar(FileName));
//Load the library!
// Attention! PChar for versions below 2009 Delphi
If LibHandle = 0 then begin
MessageBox(0,"",0,0);
exit;
end;
FirstCall:= GetProcAddress(LibHandle,"FirstCall ");
//Get a pointer to an object
//1st parameter link to the library module
//2nd parameter object name in dll

DoubleCall:= GetProcAddress(LibHandle,"DoubleCall");
If @FirstCall = nil then begin

MessageBox(0," Unable to load library",0,0);
exit;
end;
If @DoubleCall = nil then begin
//Check for the presence of this function in the library.
MessageBox(0," Unable to load library",0,0);
exit;
end; end;

After that, on the form, we create an OnCreate event handler, in which, using the newly created procedure, we will load our library

Procedure TForm1.FormCreate(Sender: TObject);
Begin
LoadMyLibrary("Project2.dll");
end;

Now again, in order to call the necessary procedures from our library, we only need to insert their names anywhere in the code. To do this, we throw 2 Button components on the form from the Standard tab and create an OnClick event handler on each

OnClick of the first button:

Procedure TForm1.Button1Click(Sender: TObject);
Begin
first call; // The name of the procedure that is in the dll
end;

OnClick of the second button:

Procedure TForm1.Button2Click(Sender: TObject);
Begin
double call; // The name of the procedure that is in the dll
end;

And finally, we create an OnDestroy event handler on the form in which we unload dll library from memory

Procedure TForm1.FormDestroy(Sender: TObject);
Begin
FreeLibrary(LibHandle);
//Unload the library from memory.
end;

That's all! The second method turned out to be quite cumbersome, but its advantage is in refining the object stored in the library.

P.S. Do you want to get ahead of all other site visitors the latest Video tutorials, Audio podcasts, articles on Delphi.
Participate in competitions and gradually join our team?!
Then right now subscribe to the free multimedia newsletter of the site site
We are already more than 3500 people!

A DLL allows you to combine reusable code into one whole. Functions from DLLs can be linked dynamically at runtime, unlike functions from Delphi packages that are statically linked at the stage of application compilation.

In order to create a DLL library, first you need to execute the File|New|Other menu command and select the DLL Wizard element on the New page of the New Item dialog.

The DLL Wizard will automatically create an empty template for the DLL. Unlike a normal module that starts with the unit keyword, a DLL module starts with the library keyword. The uses section of a DLL module requires only two packages to be included: SysUtils and Classes.

Creating a DLL function consists of several steps:

1. First, in the implementation section of the module, enter the function signature and program the code that the function executes.

3. Finally, a function that is supposed to be used not only inside the module, but also called from other applications, should be declared as exportable in the exports section.

Functions from a DLL can be called both from applications developed in Delphi and from applications written in other programming languages ​​such as C++.

The order of allocating memory for parameters and releasing it is different for different programming languages. To avoid a run-time error, the declaration of a function in a DLL and its declaration in an application must use the same parameter passing mechanism. When declaring a procedure or function, one of the following parameter passing mechanisms can be specified:

The method of parameter passing is specified through a semicolon after the function description. For instance:

function F1(X, Y, Z: Real]: Real; stdcall;.

The different parameter passing methods determine the order in which parameters are passed (left to right or right to left) and also specify who will deallocate stack memory (the called procedure or the calling procedure). When using DLLs as components called from applications in other programming languages, the appropriate call modifier should be used. For C++ applications, the stdcall call modifier is used.

In order for a function described in a DLL to be called from another application, the function must be exported. The list of all exported functions is indicated in the exports section separated by commas

and ends with a semicolon. Functions can be exported in three ways:

By the function name used in the DLL;

By function name, given as export name;

By the index assigned to the function.

In order to assign some index to a function, it should be specified in the exports section after the function name with the index keyword.

In order for the exported function to be called by a name different from the name used in the DLL, in the exports section, after the function name, you must specify the name keyword and the new export name for this function.

DLL - the library is not an executable module. To get its code, it is enough to compile the project.

library project;

SysUtils, Classes;

function F1(X, Y: Integer): Integer; stdcall;

Static Linking a DLL

A DLL can be linked either statically or dynamically. When a DLL is included, it is loaded into the application's memory.

With a static link, the DLL is loaded once when the application starts. Throughout the application's execution, the name of a function imported from a statically linked DLL points to the same function (DLL entry point) in the same DLL. All functions from the DLL that will be used in the application initially must be declared as external. In this case, you should specify, if required, a call modifier. If a function is called by index, then it must be given the name used in the application and the index of the function in the DLL.

External function declarations are made in the implementation section before these functions are used.

External announcement functions with the external keyword specifies that static linking will be used.

TForm = class(TForm)

Editl: TEdit; [Field for entering the first value)

Edit2: TEdit; (Field for entering the second value)

Edit3: TEdit; (Field for displaying the result

executing a function from a DLL)

Buttonl: TButton; (Calling a function used by name)

Button2: TButton; [Calling a function used by index)

procedure ButtonlClickfSender: TObject);

procedure Button2Click(Sender: TObject);

(Private declarations)

(Public declarations)

(Declaration of exported functions)

function Fl (i: Integer; j: Integer): Integer; stdcall;

external "projectl.dll";

function F2 (i: Integer; j: Integer): Integer; stdcall;

external "Projectl.dll index 2;

procedure TForml.ButtonlClick(Sender: TObject);

(Calling an exported function)

Edit3.Text:=IntToStr(Fl(StrToInt(Editl.Text),StrToInt(Edit2.Text) ));

procedure TForml.Button2Click(Sender: TObject);

Edit3.Text:=JntToStr(F2(StrToInt(Editl.Text),StrToInt(Edit2.Text)));

Dynamic linking of a DLL

Unlike a static link for a DLL, which occurs when an application is loaded, a dynamic link for a DLL can be made at any point in a program's execution. Once a function has been called from a DLL, it can be disabled. With the simultaneous use of several DLL-libraries, this gives a significant savings in memory. To dynamically link a DLL, use the Windows API functions. Windows API - it is a set of standard functions used to implement interaction with the operating system.

When calling a function from a dynamic-link DLL, instead of defining the function name as external in the case of static linking, you should define a new type that matches the type of the function being called and create a variable of that type.

To call a function from a dynamic-link DLL, do the following:

1. Create a new type. corresponding to the type of the called function (the name of the new type can be entered after the type section).

For instance:

TMyFl=function(i,j:Integer):Integer; stdcall;

2. In the var section of the interface section of the module, create a variable of the created function type. For example: MyFl: TMyFl;

3. Before loading the DLL, declare an Integer variable that will contain the descriptor of the included library.

4. Call the LoadLibrary method, which loads the DLL. For instance; h:=LoadLibrary("Projectl.dll");

5. Check if the library connection was successful. If the DLL name is incorrect or the DLL is not found, the LoadLibrary function will return 0.

6. In case of successful connection of the DLL library, then you should get the address of the function. For this, the GetProcAddress Windows API function is used, the parameters of which are the DLL library descriptor and the name of the plug-in function. For example: @MyFl: =GetProcAddress(h, " Fl ");

7. If the address of the function is obtained, then the value of the address (in our example @MyFl) should not be equal to nil.

8. At this point, you can call the function from the dynamically linked DLL.

9. To free and unload the DLL, call the FreeLibrary method, which unbinds the DLL.

Windows, Messages, SysUtils, Variants, Classes, Graphics,

Controls, Forms, Dialogs, StdCtrls;

TForm = class(TForm)

Button3: TButton;

procedure Button3Click

procedure TForml.Button3Click(Sender: TObject);

h:=LoadLibrary("Projectl.dll");

if h<>0 then

@MyFl:=GetProcAddress(h,"Fl");

if @MyFl<>nil then

Edit3.Text:=IntToStr(MyFl(StrToInt(Editl.Text),

StrToInt(Edit2.Text)));

Using a DLL to invoke common modal dialogs.

The result of executing a procedure from a DLL library may be the display of some modal dialog. To do this, create a form object in the exported method, display it as a modal dialog, and then delete the form object. In this case, the form itself should provide a call to the Close method to end the dialog.

To create a form, the Create method is used, as a parameter to which a pointer to the parent form, the form of the calling application, is passed. This parameter is passed to the called DLL function.

library project;

Unitl_DLL in "Unitl_DLL.pas" (Forml);

procedure MyModalForm (var Z:Integer ;F:TForm1); stdcall;

Form1:=TForml.Create(F);

(The F parameter is passed when the procedure is called and contains a pointer

to the parent form - the form of the calling application)

Due to the rapid development of programming technologies, more and more people are faced with the problem of increasing the capabilities of their programs. This article is devoted to this issue, namely, DLL programming in Borland Delphi. In addition, since we will touch on the issues of using DLLs, we will also touch on importing functions from other people's DLLs (including system ones, i.e. WinAPI).

DLL Applications

So, why are DLLs needed and where are they used?.. Here are just a few of their areas of application:

  • Separate Libraries, containing additional functions useful for programmers. For example, functions for working with strings, or complex libraries for converting images.
  • Resource stores. In a DLL, you can store not only programs and functions, but also all kinds of resources - icons, pictures, string arrays, menus, etc.
  • Support Libraries. An example is the libraries of such well-known packages as: DirectX, ICQAPI(API for ICQ), OpenGL etc.
  • Parts of the program. For example, a DLL can store program windows (forms), etc.
  • Plugins(Plugins). - That's where the real scope for the thoughts of the programmer! Plugins are additions to the program that expand its capabilities. For example, in this article we will look at the theory of creating a plugin for your own program.
  • Shared resource. DLL( Dynamic Link Library) can be used by several programs or processes at once (so-called. sharing- shared resource)

Brief description of functions and tricks for working with DLL

So, what tricks and functions do you need to use to work with a DLL? Let's analyze two methods for importing functions from the library:

1 way. Binding a DLL to a program. This is the simplest and easiest method for using functions imported from a DLL. However (and you should pay attention to this) this method has a very significant drawback - if the library that the program uses is not found, then the program simply will not start, giving an error and reporting that the DLL resource was not found. And the library will be searched: in the current directory, in the program directory, in the WINDOWS\SYSTEM directory, etc.
So, for starters - the general form of this technique:

implementation
...
function FunctionName(Par1: Par1Type; Par2: Par2Type; ...): ReturnType; stdcall; external"DLLNAME.DLL" name"FunctionName" index FuncIndex;
// or (if not a function, but a procedure):
procedure ProcedureName(Par1: Par1Type; Par2: Par2Type; ...); stdcall; external"DLLNAME.DLL" name"procedureName" index ProcIndex;

Here: FunctionName(or ProcedureName) - the name of the function (or procedure) that will be used in your program;
Par1, Par2, ...- names of function or procedure parameters;
Par1Type, Par2Type, ...- types of parameters of a function or procedure (for example, Integer);
return type- return value type (only for a function);
stdcall- a directive that must exactly match the one used in the DLL itself;
external "DLLNAME.DLL"- a directive specifying the name of the external DLL from which the given function or procedure will be imported (in this case - DLLNAME.DLL);
name "FunctionName" ("ProcedureName")- a directive that specifies the exact name of a function in the DLL itself. This is an optional directive that allows you to use a function in the program that has a name that is different from the true one (which it has in the library);
index FunctionIndex(ProcedureIndex)- a directive that specifies the ordinal number of a function or procedure in a DLL. This is also an optional directive.

2 way. Dynamic DLL loading. This is a much more complex but also more elegant method. It is devoid of the disadvantage of the first method. The only thing that is unpleasant is the amount of code required to implement this technique, and the difficulty is that the function imported from the DLL is available only when this DLL is loaded and is in memory ... You can read the example below, but for now - a short description of the WinAPI functions used by this method:

LoadLibrary(libfilename: PChar) - loading the specified library LibFileName into memory. On success, the function returns a handle ( THandle) DLL in memory.
GetProcAddress(Module: THandle; ProcName: PChar) - reads the address of the exported library function. On success, the function returns a handle ( TFarProc) functions in the loaded DLL.
freelibrary(LibModule: THandle) - invalidates the LibModule and frees the memory associated with it. It should be noted that after calling this procedure, the functions of this library are no longer available.

Practice and examples

Well, now it's time to give a couple of examples of the use of the above methods and techniques:

Now the same thing, but in the second way - with dynamic loading:

(... Here comes the file header and the definition of the form TForm1 and its Form1 instance)

var
Form1: TForm1;
GetSimpleText: function(LangRus: Boolean): PChar;
LibHandle: THandle;

procedure Button1Click(Sender: TObject);
begin
("We clean" the address of the function from "dirt")
@GetSimpleText:= nil;
(Trying to load the library)
LibHandle:= LoadLibrary("MYDLL.DLL");
(If everything is ok)
if LibHandle >= 32 then begin
(... then we are trying to get the address of the function in the library)
@GetSimpleText:= GetProcAddress(LibHandle,"GetSimpleText");
(If everything is OK here)
if @GetSimpleText<>nil then
(... then we call this function and show the result)
ShowMessage(StrPas(GetSimpleText(True)));
end;
(And do not forget to free memory and unload the DLL)
FreeLibrary(LibHandle);
end;

NOTE : You should refrain from using the string type in library functions, because there are problems with "memory sharing" when using it. You can read more about this (though in English) in the text of the empty DLL project that Delphi creates (File -> New -> DLL). So it's better to use PChar and then convert it to a string with StrPas if necessary.

Well, now let's analyze the DLL itself directly:

Placement in DLL resources and forms

In a DLL, you can place not only functions, but also cursors, pictures, icons, menus, text lines. We will not stop at this. I will only note that to load the resource, you need to load the DLL, and then, having received its descriptor, load the resource itself with the appropriate function (LoadIcon, LoadCursor, etc.). In this section, we will only briefly touch upon the placement of application windows (ie forms in Delphi) in DLLs.

To do this, you need to create a new DLL and add a new form to it (File -> New -> DLL, and then File -> New Form). Further, if the form is a dialog box (modal form (bsDialog)), then add the following function to the DLL (let's say the form is called Form1, and its class is TForm1):

If you need to place a non-modal form in the DLL, then you need to make two functions - opening and closing the form. In this case, you need to force the DLL to remember the handle to this form.

Creating plugins

Here we will not consider plugins in detail, because. the examples already given above will help you easily understand the lion's share of DLL programming. Let me just remind you that the plug-in is an addition to the program that expands its capabilities. At the same time, the program itself must necessarily provide for the presence of such additions and allow them to fulfill their purpose.

That is, for example, to create a plug-in for a graphics editor that would perform image conversion, you need to provide at least two functions in the plug-in (and, accordingly, call these functions in the program) - a function that would return the name of the plug-in (and /or its type) to add this plugin to the menu (or toolbar), plus the main function is to send and receive an image. Those. first, the program searches for plugins, then for each found one it calls its identifying function with a strictly defined name (for example, GetPluginName) and adds the desired item to the menu, then, if the user has selected this item, it calls the second function, which passes the input image (or file name, containing this image), and this function, in turn, processes the image and returns it in a new form (or a file name with a new image). That's the whole point of the plugin... :-)

Epilogue

This article shows the main aspects of using and creating DLLs in Borland Delphi. If you have any questions - send them to me by E-mail: [email protected], and even better - write in the conference of this site so that other users can see your question and try to answer it!

Karikh Nikolai. Moscow region, Zhukovsky

Abbreviation DLL stands for "dynamically linked library". Dll in Delphi This is a file containing the procedures and functions necessary for the operation of a computer program, with which the program is connected at the execution stage.

It would seem that all the necessary subroutines can be described in the body of the program, why do you need to create an additional dll file and connect to it at runtime? This is done for greater flexibility of the created program. Indeed, over time, some data processing algorithms may change. If the processing procedures will be contained in the body of the program, it will have to be recompiled and again transferred to customers with a fairly large file. Transferring a small dll file containing only a few procedures is much easier, and even automatically.

In addition, the work of the dll library is completely independent of the programming language in which it will be created. Therefore, we can entrust the creation of a dll for our program to third-party developers, without thinking about the programming languages ​​\u200b\u200bwhich they speak. All this, of course, greatly speeds up the creation and transfer of the finished project to customers.

Creating a DLL

Creating a dll in Delphi no more difficult than creating an additional module. Execute the command File -> New -> -> Other... In the dialog box that appears, select the DLL Wisard icon. As a result, Delphi will create a stub DLL project:

library project1;

( Important note about DLL memory management: ShareMem must be the
first unit in your library"s USES clause AND your project"s (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. )

uses
sysutils,
classes;

($R*.res)

begin
end
.

Choose a name for the new dll and save it to a separate folder by running the command file -> Save as... 4 files will appear in the folder, among which there will be no actual dll file. Naturally, these are just text files containing a description of the project. To create the final dll file, you need to compile the project. Execute the command project -> Compile Project. As a result, the actual dll file will appear in our folder, with which the main program will connect.

So far, this is an empty library.

...the text is currently being edited...



Introduction

Due to the rapid development of programming technologies, more and more people are faced with the problem of increasing the capabilities of their programs. This article is devoted to this issue, namely, DLL programming in Borland Delphi. In addition, since we will touch on the issues of using DLLs, we will also touch on importing functions from other people's DLLs (including system ones, i.e. WinAPI).

DLL Applications

So, why are DLLs needed and where are they used?.. Here are just a few of their areas of application:

Separate Libraries Contains additional functions useful for programmers. For example, functions for working with strings, or complex libraries for converting images. Resource Stores A DLL can store not only programs and functions, but also all sorts of resources - icons, pictures, string arrays, menus, and so on. Support Libraries Examples include libraries of such well-known packages as: DirectX, ICQAPI (API for ICQ), OpenGL, etc. Parts of a program For example, a DLL can store program windows (forms), and so on. Plugins (Plugins) That's where the real space for the programmer's thoughts! Plugins are additions to the program that expand its capabilities. For example, in this article we will look at the theory of creating a plugin for your own program. A shared resource DLL (Dynamic Link Library) can be used by several programs or processes at once (the so-called sharing is a shared resource)

Brief description of functions and tricks for working with DLL

So, what tricks and functions do you need to use to work with a DLL? Let's analyze two methods for importing functions from the library:

1 way. Binding a DLL to a program.

This is the simplest and easiest method for using functions imported from a DLL. However (and you should pay attention to this) this method has a very significant drawback - if the library that the program uses is not found, then the program simply will not start, giving an error and reporting that the DLL resource was not found. And the library will be searched: in the current directory, in the program directory, in the WINDOWS\SYSTEM directory, etc. So, for starters - the general form of this technique:


FunctionName (or ProcedureName) the name of the function (or procedure) that will be used in your program; Par1, Par2, ... names of function or procedure parameters; Par1Type, Par2Type, ... types of function or procedure parameters (for example, Integer); ReturnType return type (function only); stdcall directive, which must exactly match the one used in the DLL itself; external "DLLNAME.DLL" directive specifying the name of the external DLL from which the given function or procedure will be imported (in this case, DLLNAME.DLL); name "FunctionName" ("ProcedureName") directive that specifies the exact name of a function in the DLL itself. This is an optional directive that allows you to use a function in the program that has a name that is different from the true one (which it has in the library); index FunctionIndex (ProcedureIndex) A directive that specifies the ordinal number of a function or procedure in a DLL. This is also an optional directive.

This is a much more complex but also more elegant method. It is devoid of the disadvantage of the first method. The only thing that is unpleasant is the amount of code required to implement this technique, and the difficulty is that the function imported from the DLL is available only when this DLL is loaded and is in memory ... You can read the example below, but for now - a short description of the WinAPI functions used by this method:

LoadLibrary(LibFileName: PChar) Loads the specified library LibFileName into memory. On success, the function returns a handle (THandle) to the DLL in memory. GetProcAddress(Module: THandle; ProcName: PChar) gets the address of an exported library function. On success, the function returns a handle (TFarProc) to the function in the loaded DLL. FreeLibrary(LibModule: THandle) invalidates the LibModule and frees the memory associated with it. It should be noted that after calling this procedure, the functions of this library are no longer available.

Practice and examples

Well, now it's time to give a couple of examples of the use of the above methods and techniques:

Example 1: Binding a DLL to a Program


Now the same thing, but in the second way - with dynamic loading:


Note:

You should refrain from using the string type in library functions, because there are problems with "memory sharing" when using it. You can read more about this (though in English) in the text of the empty DLL project that Delphi creates (File -> New -> DLL). So it's better to use PChar and then convert it to a string with StrPas if necessary.

Well, now let's analyze the DLL itself directly:

Example 3. Project source MYDLL.DPR


Placement in DLL resources and forms

In a DLL, you can place not only functions, but also cursors, pictures, icons, menus, text lines. We will not stop at this. I will only note that to load the resource, you need to load the DLL, and then, having received its descriptor, load the resource itself with the appropriate function (LoadIcon, LoadCursor, etc.). In this section, we will only briefly touch upon the placement of application windows (ie forms in Delphi) in DLLs.

To do this, you need to create a new DLL and add a new form to it (File -> New -> DLL, and then File -> New Form). Further, if the form is a dialog box (modal form (bsDialog)), then add the following function to the DLL (let's say the form is called Form1, and its class is TForm1):

Example 4 Placing a Form in a DLL


If you need to place a non-modal form in the DLL, then you need to make two functions - opening and closing the form. In this case, you need to force the DLL to remember the handle to this form.

Creating plugins

Here we will not consider plugins in detail, because. the examples already given above will help you easily understand the lion's share of DLL programming. Let me just remind you that the plug-in is an addition to the program that expands its capabilities. At the same time, the program itself must necessarily provide for the presence of such additions and allow them to fulfill their purpose.

That is, for example, to create a plug-in for a graphics editor that would perform image conversion, you need to provide at least two functions in the plug-in (and, accordingly, call these functions in the program) - a function that would return the name of the plug-in (and /or its type) to add this plugin to the menu (or toolbar), plus the main function is to send and receive an image. Those. first, the program searches for plugins, then for each found one it calls its identifying function with a strictly defined name (for example, GetPluginName) and adds the desired item to the menu, then, if the user has selected this item, it calls the second function, which passes the input image (or file name, containing this image), and this function, in turn, processes the image and returns it in a new form (or a file name with a new image). That's the whole point of the plugin... :-)

Epilogue

This article shows the main aspects of using and creating DLLs in Borland Delphi. If you have any questions - send them to me by E-mail: