AccessMyLibrary provides FREE access to millions of articles from top publications available through your library.
Create a link to this page
Copy and paste this link tag into your Web page or blog:
If you're jumping onto the Windows bandwagon and learning Windows programming, you've no doubt heard about dynamic link libraries, or DLLs. Windows programming, and specifically programming DLLs, is not something you can master in an afternoon--nor is it one of life's great mysteries. Let's explore the basics of creating a DLL, and some of the issues to be aware of.
The DLL solution
First, why use DLLs? Developers are familiar with traditional library files, where functions are available for reuse in many applications. Whether you're developing applications in CA-Clipper, C, Pascal, or some other language, the process is fundamentally the same--provide your system with appropriate commands to identify the library. This allows a linker to pull referenced object code into your application's executable. All function references are resolved at link time. To change the function references, you have to relink the app; this is known as "static linking."
A consequence of static linking is that every executable that uses the library's functions must contain a complete copy of each function it references. In a single-tasking system like DOS, this isn't a problem. However, under a multi-tasking system like Windows, it's very bad idea. If you have 100K of library functions in each program and you have four programs running at once, then you're wasting 300K of RAM! Also, any updates to the library functions require relinking and redistribution of all the affected EXEs before the updates are given to users.
DLLs get rid of these problems by resolving function references at runtime. DLLs can load and unload under programmatic control. Only one instance of the DLL loads into workstation memory regardless of how many programs on that workstation concurrently use the DLL's functions. Also, client EXEs instantly reflect revisions to the DLL without needing to be relinked. Since you need only distribute the new version of the DLL, updates are much simpler. Further, DLLs aren't language-specific; you should be able to access any DLL from any Windows-compatible development system. For all of these reasons, DLLs are a major improvement over traditional static linking technology.
How DLLs fit in Windows
Before you create a DLL, let's review the Windows architecture. Windows 3.1 is a single-threaded, cooperative multi-tasking system. This means that, unlike OS/2 or Windows NT, there can only be one active thread of execution in an application. Even though an application may relinquish control to Windows, possibly allowing other applications to do background processing, only one …