Calling DLL functions

<< Click to Display Table of Contents >>

Navigation:  FindOnClick > FindOnClick For Advanced Users > Scripting >

Calling DLL functions

 

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).

 

 

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), in parameter declarations.

 

 

 

<%SBCOPYRIGHT%>