Accessing Global Variables

InstallShield 2020

Project:This information applies to InstallScript MSI projects.

A global variable is data declared outside of a function and available to any module in the script. By using global variables, you can share persistent data with event handlers, entry-point functions, and user-defined functions.

For example, if you retrieve the value of the operating system’s version in your OnBegin event handler, you can later access that global value in an entry-point function. The following script excerpt illustrates this:

// Include header file for built-in functions

#include <isrt.h>

// Include header file for event handlers and MSI APIs

#include <iswi.h>

 

    // Declare global variable

    NUMBER nvResult;

 

    // Prototype entry-point function

    export prototype MyFn(HWND);

 

function OnBegin()

    // Declare local variable

    STRING svResult;

begin

    GetSystemInfo (WINMAJOR, nvResult, svResult);

end;

 

function MyFn(hMSI)

begin

    if nvResult > 4 then

        // Code for version of Windows later than 4.0

    else

        // Code for Windows 4.0

    endif;

end;

Important:Global variables share state across all event handlers. However, if you create an InstallScript custom action for your project, global variables will not share state from the InstallScript custom action to the event-driven InstallScript code, or vice versa. Thus, if you declare a global variable in your event-driven InstallScript code, that variable would not be available to your InstallScript custom action. Similarly, if you declare a variable in your InstallScript custom action, that variable would not be available to your event-driven InstallScript code.