Declare Statement

Creates a wrapper or alias for a procedure.

Syntax

Simple form

Declare [ "library_name" [ , flags ] ] { Function | Sub } name _
  [ Is canonical_name ] [ parameter_list ]

Compound form

Declare "library_name" [ , flags ]
  { Function | Sub } name [ Is canonical_name ] [ parameter_list ]
  ...
End [ Declare ]

Parts

library_name
Optional string literal
flags
Optional—One or more equates, separated by commas.
  • %ANSI – Strings are 8-bit ANSI. Cannot use with %Unicode.
  • %CDecl – Uses the C calling convention.
  • %Unicode – Strings are 16-bit Unicode. Cannot use with %ANSI.
name
Necessary identifier
canonical_name
If library_name is given, an optional string literal, when the exported name is different.
If no library_name is given, the name of the procedure you want to alias.
parameter_list
Optional. See Parameter List for more information.
If no library_name is given, a simplified form is used.

Syntax

( required_params [ Optional optional_param [ = default ] [ , optional_params ] ] )
required_params
One or more integer literals, separated by commas. Use 1 for the first, 2 for the second, and so on. You can re-arrange the parameters in any order.
optional_param
Necessary after Optional – an integer literal.
default
Optional expression.
optional_params
Optional – One or more additional parameters, separated by commas. Each one can have a default value.
End
Completes the compound form. You can also use End Declare.

Instructions

Examples

Function aliases

Declare Function MyAlias1 Is SomeNamespace.SomeFunction
Declare Function MyAlias2 Is SomeOtherFunction(1, 2, Optional 3=False, 4=0.0)
Declare Function TwoArgs Is FourArgs(3, 2, Optional 1=0, 4=0)

Foreign library functions

Declare "user32.dll" Function BringWindowToTop(h As Int) As Int
Declare "user32.dll", %ANSI Function SetWindowText Is "SetWindowTextA" (
    h As Int, s As String ) As Int

Declare "user32.dll", %ANSI
    Function BringWindowToTop(h As Int) As Int
    Function SetWindowText Is "SetWindowTextA"(h As Int, s As String) As Int
End Declare

See also