Using this command we can call exported functions found in DLLs. There are two parts:
- BufferVar. Is a Buffer variable with the same name of the exported function to call. The structure definition of BufferVar must match the interface of the exported function. Before the call every field of BufferVar has to be set with the values to be passed in the parameters of the call. This can be done separately before the call with normal field initialization for Buffer variables or using the second optional part of APICall syntax.
- (ArrExpr). This part is used to make a quick initialization of the BufferVar before it is used to make the call. Makes the APiCall syntax to look similar to a "normal" function call. Inside the parentheses it is placed an Array expression with the values that will initialize BufferVar fields. This, in most cases, will be an inline array.
Lets say there is an exported function
int AddTwoNumbers(int n1, int n2) in a DLL 'MATH.DLL'. We assume that the function uses Windows API calling conventions. To make a call to this function first we have to create a Buffer variable with the same name as in the following code:
SET AddTwoNumbers = BUFDEF(n1:atINTEGER,n2:atINTEGER)API('MATH.DLL');
The Buffer variable created has the same name with the function and structure same with its interface. In the API section of the above syntax is defined the DLL which contains the function. Because AddTwoNumbers returns integer value we do not need to define that also. Is assumed by default. In a different case API's section second optional parameter defines the return type. Also because we assumed Windows calling convention we do not need to use the third optional parameter of API section. This calling convention is assumed by default.
We can make the call in the following ways:
The two APICall above they do exactly the same thing. They call AddTwoNumbers with parameters 100, 200 and get, at variable v, the result of the addition. As you can see the second case looks more to a usual function call. In C this would be:
NOTE: APICall always returns a value even if the called API routine it doesn't really (void in C/C++, procedure in Delphi/Pascal). In the later case the returned value is undefined and must be ignored.
Using Buffer variables, SET