The script engine can import procedures and functions from external DLL files, allowing you to extend your application by calling your own DLL functions.
How to Import a DLL Function in HEScript #
This is done with 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';This imports a function called MyFunction from CustomLib.dll. The default calling convention is register if not otherwise specified.
HEScript allows you to declare a different calling convention (stdcall, register, pascal, cdecl, or safecall) and to use a different name for the DLL function, as in the following declaration:
function MsgBox(hWnd: Pointer; lpText, lpCaption: String;
uType: Cardinal): Integer; stdcall; external "user32.dll" name 'MessageBoxW';This imports the MessageBoxW function from user32.dll (a Windows API library) and renames it to MsgBox for use in the script:
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 Examples #
The following Windows APIs 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";