Declare Statement

Language Items List

Definition:

Informs Phoenix that you will be using external procedures in a dynamic-link library (DLL).

Syntax (1):

Declare Sub name Lib libname [Alias aliasname][([argumentlist])]

Syntax (2):

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


Syntax Description


Sub Indicates that this is a procedure that does not return a value.

Function Indicates that this is a procedure that returns a value and can be used in an expression.

name The Sub or Function procedure name that is called. When naming procedures, follow the same naming conventions used for other variables in Phoenix. Function procedure names can include a type-declaration character.

For Function procedures, the procedure's data type determines the return data type. Using the
As clause after the argument list specifies the return type of the Function.

Lib Required for all declarations and indicates which DLL holds the procedure being declared.

Libname The name of the DLL that holds the declared procedure. It is a string literal.

Alias Indicates that the procedure being called is referred to by another name in the DLL. This is helpful when the external procedure and a Phoenix reserved word have the same name. You can also use Alias when a DLL procedure name is the same as a Global variable, a constant, or any other procedure in the same scope. Alias is also useful when you want to include characters in your DLL procedure name that are not allowed by Phoenix naming conventions.

Aliasname The name of the procedure contained in the DLL. It is a string literal.

argumentlist List of variables that represent arguments passed to the called Sub or Function procedure.

As type Declares the data type of a Function procedure
s return value. The argument type can be any of the following: Currency, Double, Integer, Long, Single, or String.

The argument argumentlist consists of the following syntax:

[ByVal] variable [As type] [,[ByVal] variable [As type] ] ...

The following table lists and describes the argumentlist syntax items.


Syntax Description


ByVal Specifies that the argument is passed by value, not by reference. The reserved word, ByVal, cannot be used with a variable of the following types: user-defined type, object type, or variable that is an array. When ByVal is omitted, a string descriptor is sent to the called DLL procedure. When ByVal is placed before a numeric argument variable, the argument is first converted to the numeric type specified with Declare, then it is passed. When ByVal is placed before a String argument variable, the address of the null-terminated string data is sent to the called DLL.

Variable Name of a Phoenix variable.

As type Declares the data type of variable. Valid data types include Currency, Double, Integer, Long, Single, String, user-defined, or any object type.

Details:

Use the Declare statement to declare procedures contained in a DLL.

To indicate that the Sub or Function procedure takes no arguments include empty parentheses at the end of the line, as in the following example:

Declare Sub ProcFromDll Lib library.dll ()

When an argument list appears, the number and type of arguments are checked with each call to the procedure.

See Also:

Call Statement