Calling external routines |
Top Previous |
|
Sprut4 can call external subroutines from dynamic link libraries (dlls). Define a function or procedure with external keyword to create a link between sprut4 routine and external function. Sprut4 uses stdcall calling convention. Integer parameters are passed as 4-byte signed integer. Float parameters are passed as 8-byte floating point value. String paramters are passed as a sequence of unsigned chars (pointer to the first char is passed). Olebstr parameters are passed as BSTR (pointer to BSTR for var parameters).
Syntax: procedure[function] foo(<parameters_list>)[: <result_type>] external <dll_name> name <routine_name_in_dll_export> foo - name of procedure or function. parameters_list - list of semicolon separated procedure parameters. only generic integer, float, pointer, string and olebstr types are supported. String parameters are passed read-only. to pass var string-type parameter to external procedure use olebstr type. Olebstr type is a OLE Automation BSTR. result_type - type of function returned value. only generic integer, float, pointer, olebstr types are supported. String return values must be of olebstr type. <dll_name> - constant string expression, defines file name of dynamic link library. <routine_name_in_dll_export> - constant string expression, routine name in export table of dll.
Example Visual C++
#include "stdafx.h" #include <stdio.h> #include <Windows.h> #include <OleAuto.h>
extern "C" { BSTR __declspec(dllexport) __stdcall test_func(int i, double d, BSTR str, BSTR* refstr) { wchar_t msg[1000]; swprintf(msg, 500, L"passed params:\r int: %i\r double: %f\r str: %s\n", i, d, str); BSTR myBstr = 0; myBstr = SysAllocString(msg); SysReAllocString(refstr, L"string by ref"); return myBstr; } }
Delphi
library test_params; |