Pointers

InstallShield 2019 ยป InstallScript Language Reference

A pointer is a variable that contains the address of another variable. To declare a pointer, use the keyword POINTER or WPOINTER followed by a variable name, as shown in the following two sample lines of code:

    POINTER pPointerName;

    WPOINTER pWPointerName;

To declare a pointer that will be used to access the members of a data structure, precede the keyword POINTER or WPOINTER with the structure type:

    typedef RECT

    begin

      SHORT sX;

      SHORT sY;

    end;

    

    RECT Rectangle;

    

    RECT POINTER pRect;

Use the address operator (&) to assign the address of a variable to a pointer variable:

    pPointerName = &MyStructure;

    pNum = &nvNumber;

    pString = &svString;

When you are defining a function that takes a pointer to a structure as a parameter, use the structure name with POINTER or WPOINTER in the function prototype, as shown below. Note that any function prototype that specifies a pointer to a structure as one of its parameters must be declared after the structure declaration.

       typedef RECT

    begin

      SHORT sX;

      SHORT sY;

    end;

    

    RECT Rectangle;

    RECT POINTER pRect;

    

    prototype SizeRectangle(RECT POINTER);

    

    . . .

    

    pRect = &Rectangle;

    SizeRectangle(pRect);

    

    . . .

    

    function SizeRectangle(pRectangle)

    begin

      pRectangle->sX = 10;

      pRectangle->sY = 5;

    end;

Passing Pointers to Strings to Functions that Are Implemented Outside InstallScript Code

The InstallScript compiler lets you pass pointers to Unicode or ANSI strings to functions that are implemented outside script. For example, if you want to call a DLL function that accepts pointers to strings in its parameters, the DLL function prototype would look something like the following in C or C++:

void __stdcall MyDllFunction(LPCSTR pszString);

In InstallScript, the function could be prototyped as follows:

prototype DLL.MyDllFunction(POINTER);

You can use the address-of operator (&) to call the function and pass a pointer to a string:

DLL.MyDllFunction(&myString);

When the script engine makes this function call, the data in string myString is passed through a pointer value to MyDllFunction. MyDllFunction receives a pointer to an ANSI representation of the string that is contained in myString.

The pointer type WPOINTER (or optionally wpointer or LPWSTR) lets you pass pointers to Unicode strings to functions outside of script. For example, if the DLL uses Unicode strings, you could change its prototype in C or C++ to the following:

void __stdcall MyDllFunction(LPCWSTR pszString);

In InstallScript, the only change that is required to pass a Unicode string pointer to a DLL that uses Unicode strings is the prototype, which would contain the WPOINTER type, as follows:

prototype DLL.MyDllFunction(WPOINTER);

When the DLL function is called in the running script, the engine passes a pointer to a Unicode copy of the string that is stored in myString instead of an ANSI version.

Using STRING and WSTRING Instead of Pointers

In most cases, you do not need to use pointers to pass strings to external DLL functions. The STRING and WSTRING types may be used in place of POINTER or WPOINTER. If a DLL function expects an ANSI string, you can use the STRING type; if a DLL function expects a Unicode string, you can use the WSTRING type. Using BYREF and BYVAL will allow for passing a string that either can be modified by the external DLL function or not.

Thus, if you use the following prototype for the function, an ANSI string could be passed by value or by references (modifying the prototype to BYREF as needed):

prototype DLL.MyDllFunction(byval string);

Changing the parameter type to BYVAL WSTRING allows a Unicode version of the string to be passed instead of the ANSI version.

See Also