Calling DLL functions

<< Click to Display Table of Contents >>

Navigation:  Using SyncBackPro > Technical Reference > Scripting >

Calling DLL functions

Previous pageReturn to chapter overviewNext page

 

You can import and call external DLL functions by inserting special directives on declaration of script routines, indicating library name and, optionally, the calling convention, beyond the function signature.

 

External libraries are loaded on demand, before function calls, if not already loaded (dynamically or statically). To load and unload libraries explicitly, the Windows functions LoadLibary and FreeLibrary from unit Windows can be used.

 

Pascal Syntax

 

function functionName(arguments): resultType; [callingConvention]; external 'libName.dll' [name ExternalFunctionName];

 

For example, the following declaration:

 

function MyFunction(arg: integer): integerexternal 'CustomLib.dll';

 

imports a function called MyFunction from CustomLib.dll. The default calling convention, if not specified, is register. You can declare different calling conventions (stdcall, register, pascal, cdecl or safecall) and use a different name for the DLL function. For example:

 

function MessageBox(hwnd: pointer; text, caption: string; msgtype: integer): integer; stdcallexternal 'User32.dll' name 'MessageBoxA';

 

that imports the MessageBoxA function from User32.dll (Windows API library), but will be called using MessageBox in the script.

 

Declarations can be used for functions and procedures (routines without result value).

 

Basic Syntax

 

function lib "libName.dll" [alias ExternalFunctionName] [callingConvention] functionName(arguments) as resultType;

 

For example, the following declaration:

 

function lib "CustomLib.dll" MyFunction(arg as integer) as integer

 

imports a function called MyFunction from CustomLib.dll. The default calling convention, if not specified, is stdcall. You can declare different calling conventions (stdcall, register, pascal, cdecl or safecall) and use a different name for DLL function. For example:

 

function MessageBox lib "User32.dll" alias "MessageBoxA" stdcall

(hwnd as pointer, text as string, caption as string, msgtype as integer) as integer

 

that imports the MessageBoxA function from User32.dll (Windows API library), but will be called using MessageBox in the script.

 

Declaration can be used for functions and subs (routines without result value).

 

Supported Types

 

The following data types (on arguments and result of external functions) are supported:

 

Integer

Boolean

Char

Extended

String

Pointer

PChar

Object

Class

WideChar

PWideChar

AnsiString

Currency

Variant

Interface

WideString

Longint

Cardinal

Longword

Single

Byte

Shortint

Word

Smallint

Double

Real

DateTime

 

Others types (records, arrays, etc.) are not supported. Arguments of the above types can be passed by reference, by adding var (Pascal) or byref (Basic), in parameter declarations.

 

 

 

All Content: 2BrightSparks Pte Ltd © 2003-2017