DECLARE

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > Script structure > External function declarations >

DECLARE

 

Description

 

Instruct thinBasic about a Windows API function/sub or 3rd party external DLL functions.

 

Syntax

 

DECLARE {SUB | FUNCTION} ProcName LIB "LibName" [ALIAS "AliasName"] [([Arguments])] [AS ReturnType]

 

Returns

 

None

 

Parameters

 

Name

Type

Optional

Meaning

ProcName

String

No

Is the name of the function that will be used inside you script. This name must be a unique name not yet used as variable, as equate and not be a keyword or a reserved word.

LibName

String

No

Is a string expressions representing the library where to search for the API function/sub

AliasName

String

No

Is the exact name of the function to search for inside the library.

If not indicated, ProcName parameter will be used.

Arguments


Yes

List of arguments to pass to function/sub.

Arguments must contain the name and the type of the parameter the function/sub expects. Each argument can be preceded  by an optional BYVAL or BYREF.

ReturnType


Yes

In case of function, the returning function type. See also Remarks below

 

Remarks

 

DECLARE is used to let thinBasic engine know about parameters and return type of an external function.

DLLs do not offer a way to know about those data. The only available information from a DLL is the list of function names exported by the DLL but nothing about what they expect as parameters or what is the return value.

 

When thinBasic search for "LibName.dll", the following paths sequence is used:

 

1. script_path\LibName.dll

2. script_path\Lib\LibName.dll

3. script_path\Bin\LibName.dll

4. script_path\Mod\LibName.dll

 

5. script_path\Lib\LibName\LibName.dll

6. script_path\Bin\LibName\LibName.dll

7. script_path\Mod\LibName\LibName.dll[/code]

 

11. thinBasic_path\LibName.dll

12. thinBasic_path\Lib\LibName.dll

13. thinBasic_path\Bin\LibName.dll

14. thinBasic_path\Mod\LibName.dll

 

15. thinBasic_path\Lib\LibName\LibName.dll

16. thinBasic_path\Bin\LibName\LibName.dll

17. thinBasic_path\Mod\LibName\LibName.dll

 

38. Dir_GetSystemDirectory\LibName.dll

39. Dir_GetWindowsDirectory\LibName.dll

 

40. CURDIR$\LibName.dll

 

50. Isolation path. Isolation path is a special path created on the fly when script is executed from inside a Bundled Exe.
 Usually Isolation path is created under system temp directory into a system/hidden directory

 

 

In case LibName will be indicated with a full absolute path no assumption or search sequence will be followed but the absolute path will be taken.

 

Return type can be expressed also as pointer to some data type.

For example:

... As Double PTR

... As String PTR

In this case thinBasic will return a DWORD representing a pointer to something. It is programmer responsibility to correctly use returned data.

 

Restrictions

 

See also

 

Examples

 

'---Declare WinBeep function from KERNEL32 dll library

DECLARE FUNCTION WinBeep LIB "KERNEL32.DLL" ALIAS "Beep" ( _

                                                          BYVAL dwFreq     AS DWORD, _

                                                          BYVAL dwDuration AS DWORD _

                                                         ) AS LONG

 

'---Declare AllocConsole function from KERNEL32 dll library without any parameter

DECLARE FUNCTION AllocConsole LIB "KERNEL32.DLL" ALIAS "AllocConsole" () AS LONG