Defining Constants for DLL Functions
A function might require you to pass a constant to indicate what information you want the function to return. For example, the GetSystemMetrics function takes any one of 75 constants, each specifying a different aspect of the operating system. The information returned by the function depends on which constant you passed to it. To call GetSystemMetrics, you do not have to include all 75 constants — you can include the ones you are going to use.
Note It is a good idea to define constants rather than only passing in the values they represent. Microsoft ensures the constants will remain the same in future versions, but there are no guarantees for the constant values themselves.
The constants required by a DLL function are often cryptic in nature, so you must consult documentation for the function to determine what constant to pass to return a particular value.
The following example includes the Declare statement for the GetSystemMetrics function and two of the constants it can take, and then shows how to call GetSystemMetrics from within property procedures to return the height of the screen in pixels:
Declare Function GetSystemMetrics Lib "User32" (ByVal nIndex As Long) As Long Const SM_CXSCREEN As Long = 0 Const SM_CYSCREEN As Long = 1 Public Property Get ScreenHeight() As Long ' Return screen height in pixels. ScreenHeight = GetSystemMetrics(SM_CYSCREEN) End Property Public Property Get ScreenWidth() As Long ' Return screen width in pixels. ScreenWidth = GetSystemMetrics(SM_CXSCREEN) End Property