How to call DLL functions?

The script engine call import procedure and functions from external DLL files. Thus, you can extend your publication by calling your own DLL functions. Moreover, DLL can be stored into the publication EXE file for easier deployment.

How to import a DLL function in HEScript?

This is done thanks to the external keyword.

Syntax:

procedure/function Name(parameters...): optional type; external "functionname@dllname calling convention";

Take a look at these examples:

// Win32 API used to determine an environment variable.
function GetEnvironmentVariable(lpName: string; lpBuffer: string; nSize: LongWORD): LongWORD; external "GetEnvironmentVariableA@kernel32.dll stdcall";
// Get the attributes of a file
function GetFileAttributes(lpFileName: string): LongWord; external "GetFileAttributesA@kernel32.dll stdcall";

 const
faDirectory = $00000010;

function AFileExists (const Name: String): Boolean;
var
Attr: Integer;
begin
Attr := GetFileAttributes(Name);
Result := (Attr <> -1) and (Attr and faDirectory = 0);
end;

How to store a DLL file and call it at runtime?

If your DLL file must be deployed with the publication EXE file, you can add it to the File Manager in the root folder of your publication. Thus, it will be compiled with your EXE file.

Then, you need to tell the runtime module that the DLL file is actually inside the publication thanks to the HETEMP_ prefix.

See this example:

We have a simple DLL named MyOwnDll.dll. It exports a ShowMsg procedure that will display a message box.

We added MyOwnDll.dll file to the file list. It appears in the Publication root:

root

Then we added these lines to the owndll script:

// owndll

procedure ShowMyMessage(const contents: string); external "ShowMsg@HETEMP_MyOwnDll.dll stdcall";

procedure TestDLL;
begin
ShowMyMessage("Hello World");
end;

And finally, we call owndll.TestDLL from this HTML page. Just click the following link to try the code:

Try to call the DLL

Note that the DLL is temporarily unpacked before its functions are called, and deleted when the publication closes.

img Introduction to Scripting

img Using the Script Manager

img Script Function Reference