DECLARE is deprecated and slated for removal in a future release. Use .NET Integration instead.


DECLARE Library Function_Name Arguments as ReturnType



Indicates the name of the DLL in which the function is found.


The name of the function. Using an '@' in the Function_Name allows you to call a function by a user specified alias in Xbasic, rather than its real name in the .DLL. For example, to call a Windows API functions like SetWindowTextA (which means ASCII 8 bit character version of SetWindowText ) as Swt declare the Function_Name as follows: [email protected]


The argument types with no spaces or punctuation between them. The allowed types are the following:


32 bit long


32 bit integer


16 bit short




IEEE 8 byte Double


IEEE 4 byte float


character (address of characters)


User defined type.

You can include user defined types that have more than one character in their name by putting parentheses around the type name. See the example user defined type called 'rect' that is used in the GetWindowRect function.


The return type. See the Arguments section for allowed types. Note : Extra spaces are added for readability. Remove the space from the finished statement between ReturnType and Arguments.


DECLARE declares an externally defined function (for example a Windows API function).


An external function can return a reference to data, but user defined data returned by reference by a function cannot be modified (it is treated as Constant data). For example, declare user32 [email protected] LLL(text) is no different than: declare user32 GetWindowText LLL(text)

The reason we provide aliasing is to provide a means to override behavior of a function which can take optional arguments (have multiple declarations of the same function where an argument can be either a NULL pointer (L with a value of 0) or a structure ) or to provide a means to rename a function name that is mangled (i.e. windows functions sometimes add a W or A to the end to specify UNICODE versus ASCII versions of a function). See also DeclareStruct and Type..End Type


Declare some structures to use - a rectangle and a 1024 character buffer.

declarestruct rect L1left,L1top,L1right,L1bottom
declarestruct text C1024txt

GetWindowRect returns a long, and takes long 'window' as the first argument, and a pointer to a rect structure as the second argument.

declare user32 GetWindowRect LL(rect)

We declare GetWindowText to return a long, take a long 'window' handle as the first argument and a 1024 character buffer as the second argument and a long length as the third argument.

declare user32 [email protected] LL(text) as L

Given that wnd contains a window handle, get the text of the window into a temporary variable.

temp.text = ""

The following example shows how DECLARE was used to call a TWAIN driver.

dim ftemp as P
declarestruct hwndapp L1hwndapp
declarestruct sFile C255sFile
DECLARE Eztwain3 TWAIN_AcquireToFilename L(hwndApp)(sFile)
TWAIN_AcquireToFilename(0, ftemp)

See Also