Declare Statement
Makes a wrapper for a procedure.
Syntax
One-line construct
Declare [ library_name [ , flags ] ] { Function | Sub } name _
[ Is canonical_name ] [ parameter_list ]
Block construct
Declare library_name [ , flags ]
{ Function | Sub } name [ Is canonical_name ] [ parameter_list ]
…
End [ Declare ]
Parts
library_name
- Optional string literal with the name of a compiled library, such as a dynamic link library (DLL).
flags
- Optional one or more named constants, with a comma between each.
%ANSI
– Strings are 8-bit ANSI. Cannot use with%UTF16
.%CDECL
– Uses the C calling convention.%UTF16
– Strings are 16-bit Unicode. Cannot use with%ANSI
.
name
- Mandatory name for the wrapper procedure.
canonical_name
- If
library_name
is given, an optional string literal, when the exported name is different. - If
library_name
is not given, thenname
becomes an alternative name for the procedurecanonical_named
. parameter_list
- Optional. See Parameter List for more information.
- If
library_name
is not given, then a different construct is used.Parameter list
( mandatory_params [ Optional optional_param [ = default ] [ , optional_params ] ] )
mandatory_params
- One or more integer literals, with a comma between each.
Use
1
for the first parameter,2
for the second, thru all mandatory parameters. You can write the parameters out of sequence. optional_param
- Mandatory after
Optional
– an integer literal. default
- Optional expression.
optional_params
- Optional one or more subsequent parameters, with a comma between each. Each can have a default value.
End
- Completes the block construct.
You can also use
End Declare
. - You can change the syntax of this part. See @Option Directive for more information.
Instructions
TODO
- Give procedures alternative names.
- Import procedures from compiled libraries.
- Change the sequence of parameters.
- Make mandatory parameters optional, with default values.
- Make optional parameters mandatory, or change their default values.
Examples
Alternative names
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 function libraries
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