An introduction to Windows API and DLLs!!! Part II on VBC!!! Part III coming soon
USER32.DLL --- Contains functions that control the Windows environment and the user's interface, such as cursors, menus, windows etc.
GDI32.DLL --- Contains functions that control output to the screen and other devices.
KERNEL32.DLL --- Contains functions that control the internal Windows hardware and software interface.
There are other DLLs such as COMDLG.DLL, MAPI32.DLL, NETAPI32.DLL, WINMM.DLL etc.
Using the 'Declare' statement
Calling Windows API routines requires a statement called 'Declare'.
The 'Declare' statement performs the following tasks :
Specifies where the API function is located
Identifies arguments needed by the API function by number and data type
Specifies whether or not the API function returns a value
The following format describes the subroutine procedure version of the 'Declare' statement :
| Declare Sub procName Lib "libName" [Alias "alias"] [([ByVal] var1 [As dataType] [, [ByVal] var2 [As dataType]] ... [, [ByVal] varN [As dataType])] |
Here are two examples :
| Declare Function GetWindowsDirectory Lib
"kernel32" Alias "GetWindowsDirectoryA"_
(ByVal lpBuffer As String, ByVal nSize As Long) As Long |
| Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SystemInfo) |
Here is an example for calling a simple API routine:
This example sounds the speaker
| Private Declare Function MessageBeep Lib "user32"
(ByVal wType As Long) As Long
Private Sub cmdBeep_Click() 'You need to have a command button named cmdBeep for this example to work Dim Beeper As Variant Beeper=MessageBeep(1) End Sub |