CloseFile Example

InstallShield 2016 » 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 OpenFile and CloseFile functions.

*

* OpenFile is called to open a file, which is then read into

* a list.  The file is then closed and the list is displayed.

*

* Note: Before running this script, set the preprocessor

*       constants so that they reference an existing file

*       in an existing directory.

*

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

 

#define EXAMPLE_FILE "Readme.txt"

#define EXAMPLE_DIR "C:\\Windows"

 

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

#include "Ifx.h"

 

export prototype ExFn_CloseFile(HWND);

 

function ExFn_CloseFile(hMSI)

    STRING  svLine;

    NUMBER  nvFileHandle;

    LIST    listID;

begin

 

    // Set the file mode to normal.

    OpenFileMode (FILE_MODE_NORMAL);

 

    // Open the text file.

    if (OpenFile (nvFileHandle, EXAMPLE_DIR, EXAMPLE_FILE) < 0) then

        MessageBox ("OpenFile failed.", SEVERE);

        abort;

    endif;

 

    // Create an empty string list.

    listID = ListCreate (STRINGLIST);

 

    // Read lines from the text file into the string list.

    while GetLine (nvFileHandle, svLine) = 0

        ListAddString (listID, svLine, AFTER);

    endwhile;

 

    // Close the file.

    if (CloseFile (nvFileHandle) < 0) then

        MessageBox ("CloseFile failed.", SEVERE);

    endif;

 

    // Display the text that was read from the file.

    SdShowInfoList ("","",listID);

    

end;