SilentReadData Example

InstallShield 2024 » InstallScript Language Reference

Note:To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the functions SdMakeName, SilentReadData, and

* SilentWriteData.

*

* This example script shows how to handle a custom dialog

* in a silent installation.  The resource .dll for the example

* custom dialog shown below should be stored in a compressed

* form under the Support Files/Billboards view of InstallShield.

*

* The example dialog was built from the custom dialog

* template provided with InstallShield.

*

* Dialog control IDs and other information are included in

* the RESOURCE.H file (not shown).  This file, which is included

* in the first line of the example, must be inserted in the

* InstallScript view of InstallShield.

*

* The example creates a text file called Cominit.txt.  If the

* installation runs in silent mode, SilentReadData is called

* and the custom dialog control selections are read from

* the .ISS file.  The selections are then saved in the file

* Cominit.txt as a means of demonstrating that they were

* successfully read from the .iss file.  If the installation

* runs in normal mode, the custom dialog is displayed

* and the selections are recorded in the .iss file and

* displayed in message boxes.  The initial .ISS file text is

* shown after the example script.

*

\*--------------------------------------------------------------*/

 

#include "Resource.h"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_SilentReadData(HWND);

 

function ExFn_SilentReadData(hMSI)

    BOOL bDone;

    STRING svSection, svComPort, svPulse, svTone, svDial9, svVal;

    NUMBER nvCommDialog, nCmdValue, nPulseState, nToneState;

    NUMBER nDial9State, nResult, nvHandle;

    LIST listID;

    HWND hwndDlg;

begin

 

    // Open the text file COMINIT.TXT so custom dialog selections

    // from the .ISS file can be stored in it.

    OpenFileMode (FILE_MODE_APPEND);

    OpenFile (nvHandle, "c:\\rul", "cominit.txt");

 

    // If operating in silent mode, then read from the .ISS file.

    if (MODE=SILENTMODE) then

        SdMakeName (svSection, "COMM_DIALOG", "", nvCommDialog);

        

        SilentReadData (svSection, "Result", DATA_NUMBER, svVal, nResult);

 

        if (nResult = 1) then

            // Read the data from the .ISS file. For purposes of

            // writing the results to a text file, read the

            // data as strings.

            SilentReadData (svSection, "nPulseState", DATA_STRING,

                           svPulse, nResult);

 

            SilentReadData (svSection, "nToneState", DATA_STRING,

                           svTone, nResult);

 

            SilentReadData (svSection, "nDial9State", DATA_STRING,

                           svDial9, nResult);

 

            // Store the custom dialog selections in

            // the text file COMINIT.TXT.

            svVal = "Pulse box is: " ^ svPulse;

            WriteLine(nvHandle, svVal);

 

            svVal = "Tone  box is: " ^ svTone;

            WriteLine(nvHandle, svVal);

 

            svVal = "Dial9 box is: " ^ svDial9;

            WriteLine(nvHandle, svVal);

        endif;

 

    // If not in silent mode, then call and handle the custom dialog

    // as you normally would.

    else

        listID = ListCreate (STRINGLIST);

        ListAddString (listID,  "COMM1:", AFTER);

        ListAddString (listID,  "COMM2:", AFTER);

        ListAddString (listID,  "COMM3:", AFTER);

        ListAddString (listID,  "COMM4:", AFTER);

 

        EzDefineDialog ("MYCOMDIALOG", SUPPORTDIR^"RESOURCE.DLL",

                       "COMM_DIALOG",0);

 

        bDone = FALSE;

 

        while (bDone=FALSE)

            nCmdValue = WaitOnDialog ("MYCOMDIALOG");

 

            switch (nCmdValue)

                case DLG_INIT:

                    // Initialize the back, next, and cancel button enable/disable states

                    // for this dialog and replace %P, %VS, %VI with

                    // IFX_PRODUCT_DISPLAY_NAME, IFX_PRODUCT_DISPLAY_VERSION, and

                    // IFX_INSTALLED_DISPLAY_VERSION, respectively, on control IDs 700-724

                    // and 202.

                    hwndDlg = CmdGetHwndDlg("MYCOMDIALOG");

                    SdGeneralInit("MYCOMDIALOG", hwndDlg, 0, "");

                    CtrlSetState ("MYCOMDIALOG", ID_TONE, BUTTON_CHECKED);

                    CtrlSetList ("MYCOMDIALOG", ID_COMPORT, listID);

                    CtrlSetState ("MYCOMDIALOG", ID_DIAL9, BUTTON_CHECKED);

                case OK:

                    CtrlGetCurSel ("MYCOMDIALOG", ID_COMPORT, svComPort);

                    nPulseState = CtrlGetState ("MYCOMDIALOG", ID_PULSE);

                    nToneState = CtrlGetState ("MYCOMDIALOG", ID_TONE);

                    nDial9State = CtrlGetState ("MYCOMDIALOG", ID_DIAL9);

                    nResult = NEXT;

                    bDone = TRUE;

                case BACK:

                    nResult = BACK;

                    bDone = TRUE;

                case RES_PBUT_CANCEL:

                    // The user clicked the Cancel button.

                    Do (EXIT);

                case DLG_CLOSE:

                    // The user clicked the window's close button.

                    Do (EXIT);

                case ID_PULSE:

                    nPulseState = CtrlGetState ("MYCOMDIALOG", ID_PULSE);

 

                    if (nPulseState = BUTTON_CHECKED) then

                        CtrlSetState ("MYCOMDIALOG", ID_TONE, BUTTON_UNCHECKED);

                        CtrlSetState ("MYCOMDIALOG", ID_PULSE, BUTTON_CHECKED);

                    else

                        CtrlSetState ("MYCOMDIALOG", ID_TONE, BUTTON_CHECKED);

                        CtrlSetState ("MYCOMDIALOG", ID_PULSE, BUTTON_UNCHECKED);

                    endif;

                case ID_TONE:

                    nToneState = CtrlGetState ("MYCOMDIALOG", ID_TONE);

 

                    if (nToneState = BUTTON_CHECKED) then

                        CtrlSetState ("MYCOMDIALOG", ID_TONE, BUTTON_CHECKED);

                        CtrlSetState ("MYCOMDIALOG", ID_PULSE, BUTTON_UNCHECKED);

                    else

                        CtrlSetState ("MYCOMDIALOG", ID_TONE, BUTTON_UNCHECKED);

                        CtrlSetState ("MYCOMDIALOG", ID_PULSE, BUTTON_CHECKED);

                    endif;

                case DLG_ERR:

                    MessageBox ("Unable to display dialog. Setup canceled.", SEVERE);

                    abort;

            endswitch;

 

        endwhile;

 

        EndDialog ("MYCOMDIALOG");

        ReleaseDialog ("MYCOMDIALOG");

 

        SdMakeName (svSection, "COMM_DIALOG", "", nvCommDialog);

 

        SilentWriteData (svSection, "nPulseState", DATA_NUMBER,

                        svPulse, nPulseState);

 

        SilentWriteData (svSection, "nToneState", DATA_NUMBER,

                        svTone, nToneState);

        SilentWriteData (svSection, "nDial9State", DATA_NUMBER,

                        svDial9, nDial9State);

 

        if (nPulseState = BUTTON_CHECKED) then

            MessageBox ("The Pulse button was checked.", INFORMATION);

        else

            MessageBox ("The Pulse button was unchecked.", INFORMATION);

        endif;

 

        if (nToneState = BUTTON_CHECKED) then

            MessageBox ("The Tone button was checked.", INFORMATION);

        else

            MessageBox ("The Tone button was unchecked.", INFORMATION);

        endif;

 

        if (nDial9State = BUTTON_CHECKED) then

            MessageBox ("The Dial9 button was checked.", INFORMATION);

        else

            MessageBox ("The Dial9 button was unchecked.", INFORMATION);

        endif;

 

    endif;

 

    // Close the text file COMINIT.TXT

    CloseFile (nvHandle);

 

end;

 

 

/*The following is the initial .iss file text for the above example, where <PRODUCT_GUID> represents your project's GUID, including the

surrounding braces. Note that -1001 is the numeric value of BUTTON_CHECKED and -1002 is the numeric value of BUTTON_UNCHECKED.

 

[InstallShield Silent]

Version=v9.00

File=Response File

[Application]

Name=MyDialog

Version=4.0

Company=My Software Company

[<PRODUCT_GUID>-DlgOrder]

Dlg0=<PRODUCT_GUID>-COMM_DIALOG-0

Count=1

[<PRODUCT_GUID>-COMM_DIALOG-0]

nPulseState=-1001

nToneState=-1002

nDial9State=-1001

Result=1

*/