View contents of this chapter

Using the Declare Statement

API routines are outside of VB's entire scope, so you must use Declare statement to give VB information about the API function you're calling. 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.

Procedures

Declare Sub name Lib "libname" [Alias "aliasname"][([arglist])]

Functions

Declare Function name Lib "libname" [Alias "aliasname"][([arglist])] [As type]

API Data Types

One of the reasons the API routines are difficult to call is that Windows uses a slightly different set of data types than VB. The following table lists some of the data types:

Data Type Description
ANY It accepts different kinds of data types. All ANY arguments are passed by reference, so you won't use the ByVal keyword.
ATOM Integer Data. Always passed by value.
BOOL An expression that evaluates to a Long. Always passed by value.
CHAR An expression that evaluates to a Byte. Always passed by value.
COLOREF An expression that evaluates to a Long. Always passed by value.
DWORD An expression that evaluates to a Long. Always passed by value.
NULL Long integer data types used for uninitialized values.
LPSTR, LPCSTR An expression that evaluates to a String. Described in an API routine's declaration as ByVal argument$ or ByVal argument As String.

 



© Universal Teacher Publications        INDEX Previous Screen Next Screen