Difference between revisions of "ReNamer:Pascal Script:Import functions"
Jump to navigation
Jump to search
(Categorised) |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(One intermediate revision by the same user not shown) | |||
Line 43: | Line 43: | ||
Below is a simple example of 2 imported functions from Windows API: | Below is a simple example of 2 imported functions from Windows API: | ||
− | < | + | <syntaxhighlight lang="pascal"> |
function MyGetTickCount: Longint; | function MyGetTickCount: Longint; | ||
external 'GetTickCount@kernel32.dll stdcall'; | external 'GetTickCount@kernel32.dll stdcall'; | ||
Line 54: | Line 54: | ||
MySleep(10); | MySleep(10); | ||
end. | end. | ||
− | </ | + | </syntaxhighlight> |
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. |
Latest revision as of 15:02, 8 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:
|
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.