Documente Academic
Documente Profesional
Documente Cultură
Glenn D. Jones
November 8,1995
Introduction
This tutorial will explain the basics of writing a Windows DLL. I will direct i
t at Visual Basic programmers who have decided they need to write a DLL for thei
r VB applications. However, VB programmers not are the only users of DLLs. Tho
se programmers who want to write a DLL to interface with other languages will al
so find this tutorial useful.
In addition this tutorial is specific to writing a DLL using C.
What is a Dynamic Link Library?
A Dynamic Link Library, DLL, is a library of functions callable by an applicatio
n at runtime. The application and functions within the DLL are not bound until t
he application program is executed.
Normally the functions in a DLL are for a particular purpose (internet access, g
raphing, serial port communication). They may also be a collection of functions
required by an application and only be specific to that application. This is o
nly convention, if you are writing a DLL you can put whatever functions you want
into it.
If you are going to write and distribute a DLL, you do not need to register its
name nor get an ID from anyone. You can name it whatever you want, but please t
ry to make it unique. If you call your DLL "KERNEL.DLL" you will have problems
with it (KERNEL is a Microsoft Windows DLL used to perform operating system kern
el functions).
An application can bind to a DLL in two ways:
Load Time Binding
On Call Binding
Load Time Binding loads the DLL when an application that uses it is loaded for e
xecution. Windows loads the DLL for the application.
With On Call Binding, the DLL is loaded when it is needed. If it is never neede
d by the application it will never be loaded.
Visual Basic loads DLLs when the form that contains their Declare statement is l
oaded. If a VB application places the DLL function declare in a module or on a
form that is loaded when the application is loaded, then the DLL will be bound a
t application load time. If the declare is placed in a form that is dynamically
loaded by the VB application, then the DLL will be loaded when the form is load
ed.
One last note on loading DLL's, Windows will locate a DLL in the following order
:
In memory, a DLL, once loaded, is global to all of Windows until it is unloaded.
In the directory where the application was loaded from
In the windows directory
In the windows\system directory
In directories specified in the DOS PATH