Using DLL in script...


Version 6.5.2

I want customers to be able to call a DLL from a script.

Reading the user manual, including the current version user manual, I am confused.

The goal is to allow the user to place all the DLL function defines in one script, execute the script once, on program start and now the DLL defines are in the scripter engine for all other scripts to access. That does not seem to work.

It appears every script must include the DLL defines that the script needs.

Am I missing something?



This is partially true. When you compile a script, it doesn't get "available" automatically for the scripter. It just gets compiled. To make functions of one script be accessible for other scripts, you must register such script as a library in the scripter, or "use" it as you would use it as a unit in Delphi. It depends on how your scripts are organized.

You can "use" other scripts using this mechanism:

Or you can simply register any script as a library using this code:



I will give the SelfRegisterAsLibrary a go.

Using the example from the user manual:

function MessageBox(hwnd: pointer; text, caption: string; msgtype: integer): integer; stdcall; external 'User32.dll' name 'MessageBoxA';

in a script.

I tried SelfRegisterAsLibrary(engine) and it complied without error.

In another script:

MessageBox(null,'text','caption',0);          <-OK

MessageBoxA(null,'text','caption',0);          <-Failed compile

I used SelfRegisterAsLibrary(engine, 'CustomDLL') and it complied without error.

In another script:

CustomDLL.MessageBox(null,'text','caption',0);     <-Failed compile

CustomDLL.MessageBoxA(null,'text','caption',0);     <-Failed compile

All is expect. MessageBoxA would never be found because it's not a function in script. You just declared MessageBox.

About using a name for the script-library, DLL prototype functions can't be found with a prefix because they are declared in an internal script library. You can create wrapper functions, though, that do that for you. For example:

function _MessageBox(hwnd: pointer; text, caption: AnsiString; msgtype: integer): integer;
  stdcall; external 'User32.dll' name 'MessageBoxA';
function MessageBox(hwnd: pointer; text, caption: AnsiString; msgtype: integer): integer;
  Result := _MessageBox(hwnd, text, caption, msgtype);


The user manual and the source comments are cloudy on both issues.

function SelfRegisterAsLibrary(AScripter: TatCustomScripter; AName: string = '')

      : TatScripterLibrary; overload;


///...automatically compiled. If AName is not empty, the methods and variables can also be accessible prefixed with the AName, for example: MyLibrary.MyMethod;

CustomDLL.MessageBox should work according to the above comment.

Ok, we will make it clearer in the manual.