Applies to  VB5+ 

Windows API Type Library (Win32.tlb)

Download version 0.5 (52KB; last update: November 13, 2001)
Download the complete list of declarations
Read more about the declarations

Q&A

What is a type library?

A type library declares the classes, interfaces, constants, and procedures that are exposed by an application or dynamic-link library (DLL). A type library is usually a resource in a program file; it can also be a stand-alone binary file with the extension .tlb or .olb. The References dialog box in Visual Basic lists all the type libraries registered on your system.

For more information about ActiveX components and type libraries, see the chapter Programming with Components in the Visual Basic Programmer's Guide.

What is the Windows API Type Library?

The file Win32.tlb provides declarations for many commonly used procedures, constants, and types in the Windows API. After you add the type library to a Visual Basic project, all these declarations are immediately available for you to use. It's as if you copied and pasted a big chunk of the WIN32API.TXT file into your project -- except you don't pay any resource penalty for unused declarations.

Another feature: Nearly all API constants are defined in Enum types, and many procedures take Enum parameters. This makes it very convenient to insert constants. For example, when you enter the second argument to SendMessage, Visual Basic automatically displays the message constants available in the type library:

Screenshot of the Auto List Members box

There are a few important points you should be aware of:

What's new in the latest version?

Version 0.5 is a minor update. We added the RegOpenKeyEx procedure and the following constants: KEY_ALL_ACCESS, KEY_EXECUTE, KEY_READ, and KEY_WRITE. In addition, we removed the sNullChar constant, which was erroneously declared in previous versions of the type library.

Download the complete list of procedures, constants, and types. (The lists for version 0.4 and version 0.3 are still available.)

We also welcome your suggestions for new declarations. Which API procedures do you often use?


How do I install the Windows API Type Library?

  1. Download win32.zip and extract the file Win32.tlb. You can store the extracted file anywhere on your hard drive.

  2. Create a new project in Visual Basic and choose References from the Project menu. Click the Browse button, find and select the file you just extracted, and click OK. The type library is now registered on your system.

To replace an older version of the type library, simply overwrite the file. You do not need to reregister the type library.

To add the type library to a project, open the References dialog box and place a checkmark next to the entry "32-bit Windows API declarations (ANSI)".

Screenshot of the References dialog box

How do I uninstall the Windows API Type Library?

To remove the type library from your system, delete the file Win32.tlb. The type library will no longer show up in the References dialog box in Visual Basic.

If you want, you can remove the registry entries for the type library by deleting the following registry key:

HKEY_CLASSES_ROOT\TypeLib\{CD6E8B50-033A-11D2-B805-EBE0D6230404}

What's the deal with SendMessage?

The API Text Viewer supplies the following declaration for the SendMessage DLL procedure:

Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hWnd As Long, ByVal uMsg As Long, _
    ByVal wParam As Long, lParam As Any) As Long

Since lParam is declared As Any, you can pass variables of any data type to SendMessage. This is unsafe because Visual Basic doesn't perform any type checking.

To provide type safety, the Windows API Type Library declares several aliases for SendMessage and PostMessage:

AliasLast parameter
SendMessageByVal lParam As Long
SendMessageAsStringByVal lParam As String
SendMessageAsAnylParam As Any
PostMessageByVal lParam As Long
PostMessageAsAnylParam As Any

In most cases a Long variable or constant is passed as the final parameter to SendMessage, so we made it the default.

I prefer a different declaration for a DLL procedure. What can I do?

No problem. Simply add a Declare statement for the procedure to a module. Your declaration will "shadow" the one in the Windows API Type Library. For example, if you add

Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hWnd As Long, ByVal uMsg As Long, _
    ByVal wParam As Long, lParam As Any) As Long

to a standard module, you can call SendMessage as usual:

SendMessage txtName.hWnd, EM_SETSEL, 0, ByVal -1&

The version in the type library is still available:

Win32.SendMessage txtName.hWnd, EM_SETSEL, 0, -1

(Win32 is the name of the Windows API Type Library.)

1