DECLARE

Top  Previous  Next

Syntax

DECLARE {CDECL} localname(paramlist),returntype

DECLARE {CDECL} IMPORT,apiname {ALIAS realname}(paramlist),returntype

DECLARE {CDECL} EXTERN globalname(paramlist),returntype

Description

Declares a local, external, or import function and its parameters.

Parameters

CDECL - Optional signifies the function uses the 'C' calling convention.

localname - Name of a local SUB in this source file.

apiname - Name of a function in a DLL.

globalname - Name of a global SUB in a different source file.

ALIAS realname - apiname is an alias for realname.

paramlist - Comma separated list of parameters in the format of variable as type or variable:type.

returntype - Type that function returns.

Return value

None

Remarks

Emergence BASIC uses a two pass compiler so it is not strictly necessary to declare a SUB only used in a single source file. It is supported both for backwards compatibility and readability.

The EXTERN keyword is used for multi module (multiple source file) programming. The subroutine must be marked as global using the GLOBAL statement in the source file it is contained in.

The parameter list is optional for local functions. For externals and import functions that have no parameters use an empty list ().

See Also: SUB

Example usages

'An API declare
DECLARE IMPORT,ZeroMemory ALIAS RtlZeroMemory(pvoid as POINTER,length as INT),INT
'A local declare
DECLARE MyFunction(a as INT, b as STRING),STRING
'An external function
DECLARE EXTERN MyFunction2(ff as FLOAT), FLOAT