Sheerpower can call procedures written in other programming languages as long as
they are contained in a DLL as a global routine. An example of this is
calling routines in the Microsoft provided
msvcrt.dll library.
The
call statement is used to call and execute library routines. These
routines can perform procedures so the developer does not have to write the
code from scratch.
Note:
When calling a routine, you must enclose its name in quotes.
For example: "strlen"()
. This ensures the routine's
upper and lower case formatting is preserved.
The library to which the routine belongs must have been specified in a
library statement.
Routines within a DLL are called using the
call statement, followed by a quoted
string which contains the name of the routine to be called:
Some routines take arguments. By default, most arguments are passed by their
value. Strings and arrays are always passed by reference. If you want to
explicitly pass an argument by reference (the pointer to the argument), use
the
by ref option:
myvar% = 45
call "my_routine" (myvar% by ref, myarray%() by ref)
When a routine is called, it may also return a value. The variable
_integer will hold this value if the routine returns an integer.
If the routine returns a pointer to a null-terminated character string
(char*
), you can call the routine with the prefix
char*
. After the routine completes, _string will
contain a copy of the returned string.
For example:
myvar% = 45
call "char* my_routine" (myvar% by ref, myarray%() by ref)
print 'Returned string was: '; _string
This demonstrates how _string automatically holds the returned string
when the routine is called with the char*
prefix.
The examples below uses the Microsoft provided
msvcrt.dll
library and
calls the
strlen
and
_getcwd
functions/routines.
library 'msvcrt.dll'
text$ = 'Hello there!'
call 'strlen' (text$)
print 'The length of text$ is: '; _integer
call 'char* _getcwd'()
print 'The current working directory is: '; _string