Discovering the API Using Visual Basic 6 and Visual Basic .NET
As a Visual Basic programmer, you are likely to encounter the Windows API. This article will explain in detail what the Windows API is, as well as the different implementations of the API in Visual Basic 6 and Visual Basic .NET.
Definition of the Windows API
The Windows API is a set of several hundred functions and subroutines that are located in a set of files called Dynamic Link Libraries (DLLs). You can make a function from the Windows API available to your Visual Basic program by declaring the function to be callable from your program. You can then use the Windows API function as you would any built-in Visual Basic function or a function that you have written yourself.
End users cannot access these functions; however, programmers can access the code written in the DLLs through the API and use this code in their programs. This enables you to use existent code in the DLLs and save you time in the programming development cycle. The advantage of using Windows APIs in your code is that they can save development time because they contain dozens of useful functions that are already written and waiting to be used. The disadvantage is that Windows APIs can be difficult to work with and unforgiving when things go wrong.
Windows API Library Files
The Dynamic Link Library (DLL) files that make up the Windows API are commonly located in the Windows SYSTEM subdirectory. These files are found on every PC that is running Windows, so you don’t have to worry about including them if you create a set of setup disks for distribution. The three Windows DLLs are User32.DLL, Kernel32.DLL , and GDI32.DLL.
Several smaller DLLs, known as Extension DLLs, provide functions in addition to those found in the three major DLLs. Some useful extension DLLs include the following:
Advapi32.dll | Advanced API services library supporting numerous APIs, including many security and Registry calls |
Comdlg32.dll | Common dialog API library |
Lz32.dll | 32-bit compression routines |
Mpr.dll | Multiple Provider Router library |
Netapi32.dll | 32-bit Network API library |
Shell32.dll | 32-bit Shell API library |
Version.dll | Version library |
Winmm.dll | Windows multimedia library |
Winspool.drv | Print spooler interface that contains the print spooler API calls |
USER32.DLL
Contains functions that relate to managing the Windows environment, such as:
- Handling messages between windows
- Managing cursors
- Managing menus
- Handling other non-display functions
GetCursorPos, SetWindowPos, GetParent, GetActiveWindow, SendMessage
GDI32.DLL
Graphics Device Interface library contains functions that help manage output to different devices, especially the screen.
BitBlt, DeleteObject, RoundRect, SelectObject, StretchBlt
KERNEL32.DLL
Contains functions that manage low-level operating system functions. These include:
- Memory Management
- Task Management
- Resource Handling
- File and Directory Handling
- Module Management
GetSystemDirectory, GetTempFileName, GetModuleFileName, GetVersionEx
The following pages will explain the usage of the Windows API within Visual Basic 6 and Visual Basic .NET.