Stuff About Type Libraries

In this section, we’ll take a quick look at type libraries—not those created by Visual Basic (because they’re free) but those created by hand. You’ll see how to use these handmade type libraries as development tools and as aids that will help you ensure that your coding standards are correctly applied.

A type library is where Visual Basic records the description of your ActiveX server’s interfaces. Put another way, a type library is a file, or perhaps a part of a file, that describes the type of one or more objects. (These objects don’t have to be ActiveX servers.) Type libraries do not, however, store the actual objects described—they store only information about objects. (They might also contain immediate data such as constant values.) By accessing the library, applications can check the characteristics of an object—that is, the object’s exported and named interfaces.

When ActiveX objects are exported and made public in your applications, Visual Basic creates a type library for you to describe the object’s interfaces. You can also create type libraries separately using the tools found on the Visual Basic 5 CD in TOOLS\UNSUPPRT\TYPLIB.

Type libraries can be written using a language called Object Description Language (ODL) and compiled using MkTypLib. A good way to learn a little more about ODL is to study existing type libraries. You can use the OLEVIEW tool mentioned earlier to disassemble type libraries from existing DLLs, ActiveX servers, and controls for further study.

As I just said, the object information described by a type library doesn’t necessarily have anything to do with ActiveX. Here are a couple of handy examples to show you how you might use type libraries.