[Public|Private|Protected|Friend|Protected Friend] Declare Sub name Lib "libname" [Alias "aliasname"] [([arglist])]
[Public|Private|Protected|Friend|Protected Friend] Declare Function name Lib "libname" [Alias "aliasname"] [([arglist])] [As type]
The Declare statement syntax has these parts:
Part | Description |
---|---|
Public | Optional. Entities declared with the Public modifier have public access. There are no restrictions on the use of public entities |
Private | Optional. Entities declared with the Private modifier have private access. A private entity is accessible only within its declaration context, including any nested entities. |
Protected | Optional. Entities declared with the Protected modifier have protected access. Protected access can only be specified on members of types (both regular type members and nested types), although there are different access rules for the two. A protected type member contained in a type is accessible to entities contained in a derived type, provided the access takes place through the derived type. A protected type nested in a type is accessible to entities contained in a derived type, provided the access takes place through the base type (since nested types are not inherited). Protected access is not a superset of friend access. |
Friend | Optional. Entities declared with the Friend modifier have friend access. An entity with friend access is accessible only within the program that contains the entity declaration. |
Protected Friend | Optional. Entities declared with the Protected Friend modifiers have the union of protected and friend accessibility. |
Sub | Optional (either Sub or Function must appear). Indicates that the procedure doesn't return a value. |
Function | Optional (either Sub or Function must appear). Indicates that the procedure returns a value that can be used in an expression. |
name | Required. Any valid procedure name. Note that DLL entry points are case sensitive. |
Lib | Required. Indicates that a DLL or code resource contains the procedure being declared. The Lib clause is required for all declarations. |
libname | Required. Name of the DLL or code resource that contains the declared procedure. |
Alias | Optional. Indicates that the procedure being called has another name in the DLL. This is useful when the external procedure name is the same as a keyword. You can also use Alias when a DLL procedure has the same name as a public variable, constant, or any other procedure in the same scope. Alias is also useful if any characters in the DLL procedure name aren't allowed by the DLL naming convention. |
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. |
arglist | Optional. List of variables representing arguments that are passed to the procedure when it is called. |
type | Optional. Data type of the value returned by a Function procedure; may be Byte, Boolean, Char, Short, Integer, Long, Single, Double, Decimal, Date, String (variable length only), Object or any user-defined type. Arrays of any type cannot be returned, but an Object containing an array can. |
The arglist argument has the following syntax and parts:
[Optional] [ByVal | ByRef] [ParamArray] varname[( )] [As type]
Part | Description |
---|---|
Optional | Optional. Indicates that an argument is not required. If used, all subsequent arguments in arglist must also be optional and declared using the Optional keyword. Optional can't be used for any argument if ParamArray is used. |
ByVal | Optional. Indicates that the argument is passed by value. ByVal is the default in Visual Basic. |
ByRef | Optional. Indicates that the argument is passed by reference. |
ParamArray | Optional. Used only as the last argument in arglist to indicate that the final argument is an Optional array of Object elements. The ParamArray keyword allows you to provide an arbitrary number of arguments. The ParamArray keyword can't be used with ByVal, ByRef, or Optional. |
varname | Required. Name of the variable representing the argument being passed to the procedure; follows standard variable naming conventions. |
( ) | Required for array variables. Indicates that varname is an array. |
type | Optional. Data type of the argument passed to the procedure; may be Byte, Boolean, Char, Integer, Long, Long8, Single, Double, Decimal, Date, String (variable length only), Object, a user-defined type, or an object type. |
For Function procedures, the data type of the procedure determines the data type it returns. You can use an As clause following arglist to specify the return type of the function. Within arglist, you can use an As clause to specify the data type of any of the arguments passed to the procedure.
AddressOf Operator | Call Statement | Function Statement | LastDLLError Property | Sub Statement