Some DLLs require the use of constants or user-defined types, otherwise known as
structures or
parameters . You must place these in the General Declarations section of your module, along with the Declare statements you have defined.
Constants are used by many of the API functions. They provide you with an English-like way of sending required values to an API function. You use the constant as an alias for a specific value. Here's an example:
Global Const SM_CXSCREEN = 0 Global Const SM_CYSCREEN = 1
You place the constant declarations and function declarations in the General Declarations section of a module. When the GetSystemMetrics function is called in the following example, the SM_CXSCREEN and SM_CYSCREEN constants are passed as arguments to the function:
Sub GetScreenInfo() MsgBox "Screen Resolution is : " & _ GetSystemMetrics(SM_CXSCREEN) & _ " By " & _ GetSystemMetrics(SM_CYSCREEN) End Sub
When the code in the example passes the SM_CXSCREEN constant to the GetSystemMetrics function, the function returns the horizontal screen resolution; when the code passes the SM_CYSCREEN constant to the function, the code returns the vertical screen resolution.
When working with types, you first must declare the type in the General Declarations section of a module. You then can pass elements of a user-defined type, or you can pass the entire type as a single argument to the API function. The following code shows an example of a Type declaration:
Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long strReserved As String * 128 End Type
You declare the Type structure OSVERSIONINFO in the General Declarations section of the module, as shown in Listing 23.1.
In this listing, the statement Dim OSInfo As OSVERSIONIFO creates a Type variable. The entire structure is passed to the GetVersionEx function (declared in basAPICalls), which fills in the elements of the structure with information about the operating system. The code retrieves and stores this information into variables that it displays in a message box.