Skip to content

How to call DLL functions?

The script engine can import procedure and functions from external DLL files. Thus, you can extend your application by calling your own DLL functions.

How to import a DLL function in HEScript?

This is done thanks to the external keyword.

Syntax:

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

For example, the following declaration:

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

imports a function called MyFunction from CustomLib.dll. Default calling convention, if not specified, is register.

HEScript allows to declare a different calling convention (stdcall, register, pascal, cdecl or safecall) and to use a different name for the DLL function, like the following declaration:

function MsgBox(hWnd: Pointer; lpText, lpCaption: String; 
uType: Cardinal): Integer; stdcall; external "user32.dll" name 'MessageBoxW';

This imports 'MessageBoxW' function from User32.dll (Windows API library), named 'MsgBox' to be used in script, like:

procedure TestDLL;
var
S: String; 
begin 
S := InputBox("What do you want to show?", "Query", "");
MsgBox(0, S, "You entered:", MB_OK+MB_ICONINFORMATION);
end;

Warning

Pointer and out parameters are not handled by the script engine.

Other samples

The following Windows API can be imported into the HEScript engine with these declarations:

function GetDiskFreeSpace(root: AnsiString; var secPerCluster, bytesPerCluster, freeClusters,  totalClusters: integer): boolean; stdcall; external "Kernel32.dll" name 'GetDiskFreeSpaceA';

function FindWindow(className, windowName: AnsiString): integer; stdcall; external "User32.dll" name 'FindWindowA';

function GetKeyState(virtKey: integer): smallint; stdcall; external "User32.dll";

Introduction to Scripting

Using the Script Manager

Script Function Reference