Navigation: For Developers > Extend Functionality with HEScript > Sample Scripts >

How to call DLL functions?

 

 

 

 

Extending Your Publication with DLL Functions

 

This guide will walk you through the process to extend your HTML Executable application by importing procedures and functions from external DLL files.

 

The Objective 🎯

 

The script engine in HTML Executable allows you to import procedures and functions from external DLL files, enabling you to extend your publication by calling your own DLL functions.

 

How to Import a DLL Function in HEScript? 📝

 

Importing a DLL function in HEScript is accomplished using the `external` keyword.

 

Syntax 🖋️

 

The syntax for importing a DLL function is as follows:

 

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

 

For instance, the following declaration:

 

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

 

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

 

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, like 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` (Windows API library), named `MsgBox` to be used in the 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;

 

 Please note that pointer and out parameters are not handled by the script engine.