Navigation:  Click-Script Guide > DLL Actions >

Pointer Parameters

Previous pageReturn to chapter overviewNext page

When the DLL function's definition includes pointers, you must define it in the DLL Action's definition. Setting the Variable property of the parameter, VisualSetup interprets that the parameter is a pointer.

 

 

String Pointers

 

The way the DLL functions returns strings is using pointers. VisualSetup allows you call these DLL functions using DLL actions. As you need to do in your programming language, before calling this kind of DLL function, first you must to allocate a string buffer, call the DLL function and then release the buffer. Click-script includes the actions Allocate String Buffer and Release String Buffer to do this work for you.

The following example shows the definition of a Windows API function named GetEnvironmentVariable used to retrieve the contents of a specified variable from the environment block of the calling process.

 

Example: GetEnvironmentVariable

Name = Get Environment Variable

Description = Retrieves the contents of the specified variable from the environment

block of the calling process.

Type = LongInt

Unicode = False

FileName = %SysDir%\kernel32.dll

FunctionName = GetEnvironmentVariableA

ParamsCount = 3

 

[Parameter 1]

Name = Name

Description = Environment variable name

Type = String

Variable = False

 

[Parameter 2]

Name = Buffer

Description = Buffer for variable value

Type = String

Variable = True

 

[Parameter 3]

Name = Size

Description = Size of buffer

Type = LongInt

Variable = False

 

The second parameter of the definition above is a string pointer. Now, to call this DLL action to read environment variable My Variable, first you must to allocate a string buffer using the click-script action and then call the DLL action, as the following example:

 

Allocate String Buffer ( String Variable =  %EnvVariable% , Index =  0 , Character's Number =  4096 )
Get Environment Variable ( Result =  (No Variable) , Name =  My Variable , Buffer =  %EnvVariable% , Size =  4096 )
Release String Buffer ( String Variable =  %EnvVariable% , Index =  0 )

 

After executing the script above, the variable %EnvVariable% will contain the value of the My Variable environment variable.

 

 

Arrays

 

VisualSetup, exactly as C / C++ does, considers that an array is an pointer. So, if you define a DLL action with a variable parameter (pointer), and defines its value to an array, VisualSetup will call the DLL function passing the array to the function.

For example, let's suppose we have a DLL function named CalculateSUM, and this function calculates the sum of the elements of an array, like the following example.

 

Example: CalculateSUM (C / C++)

long int CalculateSUM (long int* elements, long int total)

{

   long int sum = 0;

   for (long int i = 0; i < total; i++)

       sum += elements[i];

   return rum;

}

 

Example: CalculateSUM (Delphi)

function CalculateSUM (elements: ^LongInt; total: LongInt): LongInt;

var

  i: LongInt;

begin

    CalculateSUM := 0;

    for i := 0 to total - 1 do

         CalculateSUM := CalculateSUM + elements[i];

end;

 

The correspondent definition of the DLL action will be:

 

Example: CalculateSUM

Name = Calculate SUM

Type = LongInt

ParamsCount = 2

 

[Parameter 1]

Name = Elements

Type = LongInt

Variable = True

 

[Parameter 2]

Name = Total

Type = LongInt

Variable = False