
Bye Bye DLL hell
(or how to link DLLs statically in Delphi)
Synopsis
This article describes step for step the creation of a "real"
Delphi unit out of nearly any DLL, which will be linked and loaded as
any other unit without any external dependencies.
Credits
The method to integrate a DLL into Delphi and the DLLLoader and DLL2pas
utilities were created by Benjamin Rosseaux (www.0ok.de,
benjamin@0ok.de), who did nearly
all the work
To achieve the following results, you have to download
the DLLTools and expand them into any directory.
If there does already exist a dynamical loader (a unit which loads DLL
entries into pointers) it can be converted to a static Delphi unit with
the following steps:
| 1. |
Task
Copy the DLL into the DLLTools subdirectory and open a command shell
there. To simplify this task, you may just double click onto shell.bat.
Result
The DLL resides in the DLLTools directory, and you can use the command
shell there :^)
|
| 2. |
Task
Start DLL2PAS with the name of the DLL without extension and the
name of the dynamical loader. Use capitals in the way you want them
in the resulting unit.
Example
dll2pas ODE DynODE.pas
Result
You get a Pascal unit with the same name as the DLL
|
| 3. |
Task
Delete any unneeded parts (such as loading and unloading routines)
since this task will be done automatically in our newly created unit.
transfer the implementations of any "real" Delphi routines.
Result
We have a static import library for our DLL |
If there is only a static loader for the DLL, you can create code sequences
for dynamical loading this way:
Task
Copy the declaration of all functions (and only the functions) into a
file named input.txt into to DLLTools directory. Now call the program
Static2DynDLL
Result
You get the files 0pointers.txt, 0load.txt and 0setnil.txt which can be
used to create a dynamic import library.
Notice
If a function declaration spans several lines, you might have to edit
the created source, since Static2DynDLL isn't too intelligent
Tip
You can call DLL2PAS with just the name of the DLL and insert the code
sections created by Static2DynDLL manually
The download of the DLLTools already contains static import libraries
for the physic engines ODE (v0.5) and Newton (v1.24). Adaption of newer
versions or other DLLs should be easy. The ODE and Newton DLLs are also
included, so that you can reproduce the results yourself - of course those
aren't needed anymore with our newly created import libraries.
Stay tuned and have fun,

|