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 use 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
While Sheerpower prevents common failure modes such as stack overflows and memory corruption
within your business logic, DLL routines execute as native code and can still fail or crash if
implemented incorrectly. Use only well-tested system libraries (like msvcrt.dll) or
thoroughly validated custom DLLs.
(Show/Hide Sheerpower External Calls Takeaways)
Sheerpower External Calls Takeaways
- Sheerpower can call routines in external DLLs using the
library and call statements.
- Routine names must be quoted (e.g.,
"strlen"())
to preserve case sensitivity.
- Arguments are passed by value by default; strings and arrays
are always passed by reference.
- Use
by ref explicitly when you need to pass
argument pointers.
- If a routine returns an integer, the value is stored in
_integer.
- If a routine returns a
char* string, prefix the
call with char*; the result is stored in
_string.
- Common examples include calling C runtime functions like
strlen and _getcwd from
msvcrt.dll.
- This feature allows Sheerpower programs to leverage existing
libraries without rewriting functionality.