Calling DLL functions

<< Click to Display Table of Contents >>

Navigation:  Using SyncBackPro > Technical Reference > Scripting >

Calling DLL functions

 

You can import and call external DLL functions by adding special directives to the declaration of a script routine. In addition to the function signature, the directive specifies the library name and, optionally, the calling convention.

 

External libraries are loaded automatically the first time one of their functions is called, unless the library is already loaded. To load and unload libraries explicitly, the Windows API functions LoadLibrary and FreeLibrary can be used.

 

Note: the DLL must match the bitness of SyncBackPro. A 64-bit installation of SyncBackPro can only load 64-bit DLLs, and a 32-bit installation can only load 32-bit DLLs. See 32-bit vs 64-bit.

 

 

Pascal Syntax

 

The declaration syntax when using the Pascal scripting language is:

 

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';

 

This imports the MessageBoxA function from User32.dll (a Windows API library), but it is called as MessageBox in the script.

 

Declarations can be used for both functions and procedures (routines that do not return a value).

 

 

Basic Syntax

 

The declaration syntax when using the Basic scripting language is:

 

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 the 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

 

This imports the MessageBoxA function from User32.dll (a Windows API library), but it is called as MessageBox in the script.

 

Declarations can be used for both functions and subs (routines that do not return a value).

 

 

Supported Types

 

The following data types are supported for the arguments and result of external functions:

 

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

 

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

 

 

 

All Content: 2BrightSparks Pte Ltd © 2003-2026