Difference between revisions of "ReNamer:Pascal Script:Import functions"

From den4b Wiki
Jump to navigation Jump to search
(Created page with 'This article describes how to declare and call external functions from within Pascal Script. You would need to know few bits of information about the e...')
 
(Categorised)
Line 1: Line 1:
 +
{{Up|ReNamer:Pascal Script}}
 +
 
This article describes how to declare and call external functions from within [[ReNamer:Pascal Script|Pascal Script]].
 
This article describes how to declare and call external functions from within [[ReNamer:Pascal Script|Pascal Script]].
  
Line 55: Line 57:
  
 
The script will assign a current timestamp to each filename, with a small pause after each processed file.
 
The script will assign a current timestamp to each filename, with a small pause after each processed file.
 +
 +
[[Category:ReNamer]]
 +
[[Category:Pascal Script]]

Revision as of 11:17, 5 February 2017

This article describes how to declare and call external functions from within Pascal Script.

You would need to know few bits of information about the external function that you are trying to use. You can usually find all this information in the documentation to the libraries where function is stored. But first, we will see the syntax for external declarations in Pascal Script.

function <MY-NAME>(<PARAMETERS>):<RETURN> external '<NAME>@<DLL> <CALL>';

And similar declaration for the procedure (function without return):

procedure <MY-NAME>(<PARAMETERS>) external '<NAME>@<DLL> <CALL>';

Now, what do all those tags in brackets mean:

<MY-NAME> Name which will be used in Pascal Script to refer to the function. This you can come with your-self.
<PARAMETERS> List of parameters with their types, taken from function specification and converted into syntax of Pascal Script.
<NAME> Original name of the exported function.
<DLL> Library name where the function is stored. Usually file with *.DLL extension.
<CALL> Calling convention used by the function. This is a tricky one. Calling conventions can differ based on programming language, API specifications, developer's choice, etc. Here is a list of calling conventions with some advices:
  • register - default, used by Delphi / Pascal Script.
  • stdcall - standard calling convention for Windows API.
  • cdecl - used by shared libraries written in C or C++.
  • pascal - maintained for backward compatibility.

Examples

Below is a simple example of 2 imported functions from Windows API:

function MyGetTickCount: Longint;
  external 'GetTickCount@kernel32.dll stdcall';

procedure MySleep(Milliseconds: Cardinal);
  external 'Sleep@kernel32.dll stdcall';

begin
  FileName := IntToStr(MyGetTickCount);
  MySleep(10);
end.

The script will assign a current timestamp to each filename, with a small pause after each processed file.