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

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

 
 Discussion by Clinica do PC with 0 Replies.
 Last Update: March 21, 2008, 2:19 am
 
bookmark - Creating Dll With Delphi show how to pass functions and procedures in DELPHI  
    
free web hosting
 
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

Fri Mar 21, 2008    Reply    New Discussion   


Quickly Post to Creating Dll With Delphi show how to pass functions and procedures in DELPHI w/o signup Share Info about Creating Dll With Delphi show how to pass functions and procedures in DELPHI using Facebook, Twitter etc. email your friend about Creating Dll With Delphi show how to pass functions and procedures in DELPHI Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Drawing Basic Rectangles Using Java!  Drawing Basic Rectangles Using Java! (0) (0) How To Call A Dll From Delphi Last article I showed how to create a DLL, now we are going ...  How To Call A Dll From Delphi Last article I showed how to create a DLL, now we are going to learn h