You can also use of Declare for referencing external routines. See below for details.
Platform Notes:
Windows
Under Windows, external routines are contained in DLLs. The libraries containing the routines are loaded when the routine is called for the first time (i.e., not when the script is loaded). This allows a script to reference external DLLs that potentially do not exist.
All the Windows API routines are contained in DLLs, such as "user", "kernel", and "gdi". The file extension ".exe" is implied if another extension is not given.
If the libname$ parameter does not contain an explicit path to the DLL, the following search will be performed for the DLL (in this order):
1. The current directory 2. The Windows directory
3. The Windows system directory 4. The directory containing WM Basic
5. All directories listed in the path environment variable
If the first character of aliasname$ is #, then the remainder of the characters specify the ordinal number of the routine to be called. For example, the
following two statements are equivalent (under Windows, GetCurrentTime is defined as ordinal 15 in the user.exe module):
Declare Function GetTime Lib "user" Alias "GetCurrentTime" () As Integer
Declare Function GetTime Lib "user" Alias "#15" () As Integer
Under Windows, the names of external routines declared using the CDecl
keyword are usually preceeded with an underscore character. When WM Basic searches for your external routine by name, it first attempts to load the routine exactly as specified. If unsuccessful, WM Basic makes a second attempt by prepending an underscore character to the specified name. If both attempts fail, then WM Basic generates a runtime error.
Windows has a limitation that prevents Double,Single, and Date values from being returned from routines declared with the CDecl keyword. Routines that return data of these types should be declared Pascal.
Platform Notes:
Macintosh
On the Macintosh, external routines are implemented in code resources. If a code resource does not contain an explicit folder name, then WM Basic looks in the following areas:
1. The current folder
2. The folder containing the application
3. The Extension folder within the System folder
When using the C calling convention (with the CDecl keyword), WM Basic assumes 4-byte integers (the int data type in C). This may be problematic, as some compilers on the Macintosh assume 2-byte integers.
On the Macintosh, the code resource type is specified in aliasname$ as follows:
"[ResourceType]$[ResourceName]"
Parameter Description
ResourceType Any valid four-character name containing the type of the resource. If this parameter is omitted, then CODE is assumed.
ResourceName Name of the procedure in the code resource. If this parameter is omitted, then ResourceName is assumed to be the same as name.
On the Macintosh, the format for parameters passed to external code resources is different than on other platforms. The differences only occur when using the Pascal calling convention (i.e., when the CDecl keyword is omitted). The following list describes these differences:
Singles, doubles, and dates passed by value or by reference are passed as a 32-bit pointer to a 10-byte value—an extended type. When passed by value, modification of the extended type does not change the original value in WM Basic.
Variants passed by value are passed as a 32-bit pointer to the internal variant structure used by WM Basic. Modifications to this internal structure do not affect the original value of the variable in WM Basic.
Currencies passed by value are passed as a 32-bit pointer to an 8-byte integer scaled by 10000.
Chapter 2 DefType (statement) 153
DefType (statement)
Syntax DefInt letterrange DefLng letterrange DefStr letterrange DefSng letterrange DefDbl letterrange DefCur letterrange DefObj letterrange DefVar letterrange DefBool letterrange DefDate letterrange
Description Establishes the default type assigned to undeclared or untyped variables.
Comments The DefType statement controls automatic type declaration of variables.
Normally, if a variable is encountered that hasn't yet been declared with the Dim, Public, or Private statement or does not appear with an explicit type-declaration character, then that variable is declared implicitly as a variant (DefVar A–Z). This can be changed using the DefType statement to specify starting letter ranges for type other than integer. The letterrange parameter is used to specify starting letters. Thus, any variable that begins with a specified character will be declared using the specified Type.
The syntax for letterrange is:
letter [-letter] [,letter [-letter]]...
DefType variable types are superseded by an explicit type declarationusing either a type-declaration character or the Dim, Public, or Private
statement.
The DefType statement only affects how WM Basic compiles scripts and has no effect at runtime.
The DefType statement can only appear outside all Sub and Function declarations.
The following table describes the data types referenced by the different variations of the DefType statement:
Statement Data Type DefInt Integer DefLng Long DefStr String DefSng Single DefDbl Double DefCur Currency DefObj Object DefVar Variant DefBool Boolean DefDate Date Example DefStr a-l
DefLng m-r DefSng s-u DefDbl v-w DefInt x-z
Const crlf = Chr$(13) + Chr$(10) Sub Main()
a = 100.52 m = 100.52 s = 100.52 v = 100.52 x = 100.52
msg = "The values are:"
msg = msg & "(String) a: " & a msg = msg & "(Long) m: " & m msg = msg & "(Single) s: " & s msg = msg & "(Double) v: " & v msg = msg & "(Integer) x: " & x MsgBox msg
End Sub
See Also Currency (data type); Date (data type); Double (data type); Long (data type);
Object (data type); Single (data type); String (data type); Variant (data type); Boolean (data type); Integer (data type).
Platform(s) Windows and Macintosh.