Applies to VB5+ |
Download version 0.5 (52KB; last update: November 13, 2001)
Download the complete list of declarations
Read more about the declarations
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.
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:
There are a few important points you should be aware of:
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.)
note | In version 0.4, we replaced the FILETIME type with the Currency type. |
We also welcome your suggestions for new declarations. Which API procedures do you often use?
note | If you're running Windows NT or Windows 2000, you may need to log on as an administrator before you can register the type library. |
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)".
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}
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:
Alias | Last parameter |
---|---|
SendMessage | ByVal lParam As Long |
SendMessageAsString | ByVal lParam As String |
SendMessageAsAny | lParam As Any |
PostMessage | ByVal lParam As Long |
PostMessageAsAny | lParam As Any |
In most cases a Long variable or constant is passed as the final parameter to SendMessage, so we made it the default.
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.)
Copyright © 2001 Rising Productions. Last update: November 20, 2001