Declare

This statement is used at module level to declare references to external procedures in a dynamic-link library (DLL).

Syntax 1

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

Syntax 2

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

Parameters

name
Required. Any valid procedure name. Note that DLL entry points are case sensitive.
libname
Required. Name of the DLL that contains the declared procedure.
aliasname
Optional. Name of the procedure in the DLL or code resource. If the first character is not a number sign (#), aliasname is the name of the procedure's entry point in the DLL. If # is the first character, all characters that follow must indicate the ordinal number of the procedure's entry point. If you do not specify aliasname, use name as the name of the procedure’s entry point.
arglist
Optional. List of variables that represents parameters passed to the procedure when the procedure is called.

The arglist parameter has the following syntax:

[ByVal | ByRef] varname [As type]

varname
Required. Name of the variable that represents the parameter being passed to the procedure. You cannot pass arrays. All strings are passed as Unicode.
type
Optional. Data type of the parameter passed to the procedure. The data type can be Byte, Boolean, Integer, Long, String, or Variant. If you do not specify type, varname is a Variant by default.
type
Required. Data type of the value returned by a Function procedure. The data type can be Byte, Boolean, Integer, Long, String, or Variant.

Remarks

All functions in a module are public. The Private keyword is unsupported. Declarations for functions require that you specify a return type. Unlike function parameters, return types do not default to Variant.

Use ByVal to pass a parameter by value. Use ByRef to pass a parameter by reference. ByRef is the default way a parameter is passed to a function.

Declaring a variable As Any is unsupported. You must specify one of the supported types or use the default Variant type.

Use the vbNullPtr constant when calling external procedures, where the external procedure requires a pointer value of 0. This is not the same as a zero-length string ("").

Declare supports the following data types: Byte, Boolean, Integer, Long, String, or Variant. The Optional and ParamArray keywords are unsupported.