The advantages of creating and using DLLs in VB6

In VB, you create a Dynamic Link Library (DDL) by selecting ActiveX DLL from the New Project dialog box. This tip highlights the various uses and benefits of using DLLs.

A Dynamic Link Library (DDL) is a file that contains compiled code. In this sense, it's like an executable program (i.e., an EXE file), but there is one major difference: Once a DLL is installed and registered on a system, its code is available to any program that calls it. This can be an advantage when you're writing multiple programs that will usually be installed together. By placing shared code in a DLL, you can decrease program size and simplify the task of upgrades, and also make the code easily reusable in other projects.

Another use for DLLs is in Web programming. Active Server Page (ASP) technology lets you include code in your Web pages to provide dynamic functionality and database access, but the ASP code is viewable by anyone who visits your site. If you want to hide your code so that others cannot "borrow" it for their own use, you can create a DLL and install it on the server. Then, your ASP page can call the DLL as needed, so the full functionality is available without exposing your source code to others.

In VB, you create a DLL by selecting ActiveX DLL from the New Project dialog box. The new project will contain a single class module, which illustrates how VB DLLs work. A DLL that you create will contain one or more classes, which are essentially identical to the classes you can create in a standard VB EXE project. When a program calls a DLL, it will actually be making use of the DLL's classes and their methods and properties. An ActiveX DLL can contain forms and other components as well, but classes are at the heart of their functionality.

The VB online documentation contains a lot of background information as well as a tutorial on ActiveX DLLs. I recommend reviewing this material before deciding whether there's a place for DLLs in your VB projects.

Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!

Editor's Picks

Free Newsletters, In your Inbox