ReadBytes 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 ReadBytes and SeekBytes functions.
*
* SeekBytes is called to position a file pointer to a
* specific location in a file that has been opened in binary
* mode. ReadBytes then reads a specific number of bytes,
* starting at this location. The bytes are read into a string,
* which is then displayed in a message box.
*
* Note: The defined constants EXAMPLE_DIR and EXAMPLE_BIN must
* be set to an existing directory and file on the target
* system.
*
\*--------------------------------------------------------------*/
#define EXAMPLE_DIR "C:\\"
#define EXAMPLE_BIN "Example.bin"
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_ReadBytes(HWND);
function ExFn_ReadBytes(hMSI)
STRING svString;
NUMBER nvFileHandle;
begin
// Set the file mode to read/write.
OpenFileMode (FILE_MODE_BINARY);
// Open a binary file.
if (OpenFile (nvFileHandle, EXAMPLE_DIR, EXAMPLE_BIN) < 0) then
// Report an error; then abort.
SprintfBox (SEVERE, "CopyBytes Example", "Could not open %s.",
EXAMPLE_BIN);
abort;
endif;
// Set the file pointer to the 16th byte in the file.
SeekBytes (nvFileHandle, 15, FILE_BIN_START);
// Read the next twenty-eight bytes into svString.
if (ReadBytes (nvFileHandle, svString, 0, 28) < 0) then
// Report an error.
MessageBox ("ReadBytes failed.", SEVERE);
else
// Display the string.
SprintfBox (INFORMATION, "ReadBytes Example", "Bytes read: %s",
svString);
endif;
// Close the file.
CloseFile (nvFileHandle);
end;