Jump to content
xisto Community
Clinica do PC

Creating Dll With Delphi show how to pass functions and procedures in DELPHI

Recommended Posts

First of all, I'd like to apologise because my English is not tha good.

 

Well, It's a very popular doubt. like

How can I use a DLL? How can I create one? What is it for?

 

So, DLL or Dynamic Link Libraries, allows a set of functions developed in one especific programmer language to be used for softwares developed in other language.

 

For example, you can create a DLL in DELPHI and use it with a software developed in C++ for example.

So, let's get started:

 

Select the Item NEW in the menu FILE to show the dialog box NEW ITEMS. Now select DLL and OK to generate the main code of the DLL. This one below:

 

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;

begin

end.

 

(In many situations, including this, the file DELPHIMM.DLL should be distributed with the application)

 

Let's continue creating our DLL. Just to show let's create a function which receives as parameters two real numbers and returns the greater from them. Lets see:

 

Function Max (a b : double ) : double ; Export ; stdcall ;

begin

If (a > :) then Result :=a else Result := b ;

end ;

 

Export = indicate that the function can be used for others applications

 

Stdcall = allow applications, developed in other languages, to call the function

 

After alterations, save the project as MAXDLL.

This is how it should be:

 

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;

function Max(a, b : double):double:expert:stdcall:

begin

if (a > :) then result:= a else result := b;

end;

 

exports

Max index 1;

begin

end.

 

The DLL was created and the function inside it. You can also create procedures, etc. This is a very simple example..

In the Next Article I'll show how to call this DLL from DELPHI Source Code.

 

SEE YA

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.