Creating Packages and DLLs

From RAD Studio
Jump to: navigation, search

Go Up to Building Applications, Components, and Libraries Index

Dynamic link libraries (DLLs) are modules of compiled code that work in conjunction with an executable to provide functionality to an application. There are two typical uses of dynamic link libraries. The first is to use a repository of external DLLs written by a third party (for example, Microsoft). The second is to write your own DLLs that you want to share between your programs, and another application in a different programming language. A good example of how to use a third party's DLLs in RAD Studio is how Delphi uses the Microsoft Windows interface.

Look in the installed sources for RAD Studio:

C:\Program Files (x86)\Embarcadero\Studio\21.0/source/Win32/rtl/win/

In the WinInet.pas file, look for:

winetdll = 'wininet.dll';

Following this definition are several references to procedures in this dll:

function CommitUrlCacheEntry;          external winetdll name 'CommitUrlCacheEntryW';
function CommitUrlCacheEntryA;          external winetdll name 'CommitUrlCacheEntryA';
function CommitUrlCacheEntryW;          external winetdll name 'CommitUrlCacheEntryW';

CommitUrlCacheEntry is the name RAD Studio uses to reference the first procedure. CommitUrlCacheEntryW is the name of the procedure in wininet.dll. RAD Studio will then put Wininet in the uses clause and start using CommitUrlCacheEntry. wininet.dll must be in the current directory, or in the system PATH defined in the Environment Variables.

The interface for the CommitUrlCacheEntryW dll can be examined through the MSDN website:

WinINet Functions (MSDN)

The second use of DLLs is to write your own DLLs to be used in a program outside of RAD Studio. Create a new project in the app like this:

File > New > Other > Delphi Projects > Dynamic-link Library

File > New > Other > C++Builder Projects > Dynamic-link Library

Compile and build a DLL by using Run/Parameters, and browse for the executable of the host application.

Packages are special DLLs used by Delphi applications, the IDE, or both. There are two kinds of packages: runtime packages and design-time packages. Runtime packages provide functionality to a program while that program is running. Design-time packages extend the functionality of the IDE.

DLLs and libraries should handle all exceptions to prevent the display of errors and warnings through Windows dialogs.

The following compiler directives can be placed in library project files:

Compiler directives for libraries :

  Compiler Directive         Description
{$LIBPREFIX 'string'} Adds a specified prefix to the output file name. For example, you could specify {$LIBPREFIX 'dcl'} for a design-time package, or use {$LIBPREFIX} to eliminate the prefix entirely.
{$LIBSUFFIX 'string'} Adds a specified suffix to the output file name before the $LIBVERSION string, if present, and the extension. For example, use {$LIBSUFFIX '-mytools'} in something.dpr to generate something-mytools.bpl.
{$LIBVERSION 'string'} Adds a version extension to the output file name preceding the .bpl extension. For example, use {$LIBVERSION '2.1.3'} in something.dpr to generate something.2.1.3.bpl.

For more information on packages, see Working with Packages and Components - Overview

Tip: To upgrade a package to a new release, with no need to update the libsuffix value use the $LIBSUFFIX AUTO option. For more information, see Compiler directives for libraries or shared objects.

Topics

See Also