DECLARE
Syntax
Arguments
- Library
Indicates the name of the DLL in which the function is found.
- Function_Name
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: Swt@SetWindowsTextA
- Arguments
The argument types with no spaces or punctuation between them. The allowed types are the following:
- "L"
32 bit long
- "I"
32 bit integer
- "W"
16 bit short
- "B"
byte
- "N"
IEEE 8 byte Double
- "F"
IEEE 4 byte float
- "C"
character (address of characters)
- "(yourtype)"
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.
- ReturnType
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.
Description
DECLARE declares an externally defined function (for example a Windows API function).
Discussion
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 GetWindowText@GetWindowText 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
Examples
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 gwt@GetWindowText LL(text) as L
Given that wnd contains a window handle, get the text of the window into a temporary variable.
temp.text = "" gwt(wnd,temp,1024)
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) ftemp.sFile="C:\\test\\pict1.jpg" TWAIN_AcquireToFilename(0, ftemp)
See Also