Declaring Functions

InstallShield 2013

The first step in creating a user-defined function is to declare the function. The keyword prototype tells the InstallShield script compiler that the line contains a function definition.

To declare a function:

1. Type the keyword prototype.
2. Type the function’s return type. (This step is optional. If you do not enter a return type, it is assumed that the function returns a NUMBER value or no value.) To specify that the function does not return a value, type void.
3. On the same line, enter the function name.
4. After the function name, type the data types of the parameters, and enclose them in parentheses and separate them by commas.
5. If there are no parameters, put empty parentheses to the right of the function name.
6. End the line with a semicolon (;).

In the following examples, FunctionName is a function containing three parameters. The arguments passed when calling FunctionName must be, in order, INT, STRING, and SHORT. CopyBitmapExample has no parameters. FileTransfer has five parameters—three LONG variables and two STRING variables—and returns a NUMBER value.

prototype FunctionName (INT, STRING, SHORT);

prototype CopyBitmapExample( );

prototype NUMBER FileTransfer (LONG, LONG, LONG, STRING, STRING);

When you are declaring DLL functions, use the format <DLL file name>.<function name> for the name of the DLL file function. For example:

prototype MyDLL.MyFunction(INT, INT);

The above declaration signals to the InstallScript compiler that the program will call a function named MyFunction, with two INT parameters, in a file named Mydll.dll.

You can also optionally declare a calling convention, either cdecl or stdcall, when declaring a DLL file function. For example:

prototype cdecl MyDLL.MyFunction(INT, INT);

If you do not explicitly declare a calling convention, InstallShield uses stdcall. If you explicitly declare both a calling convention and a return type, place the calling convention before the return type.

Note: Most Windows API functions use the stdcall calling convention, but some C or C++ development environments build DLL file functions with the cdecl calling convention unless you prototype your C or C++ function with the __stdcall modifier. For more information, consult your compiler documentation.

Many Windows API functions are declared in the header file ISRTWindows.h, which is automatically included when you include Ifx.h in your script. (You can prevent the automatic definition of Windows APIs by placing the preprocessor constant ISINCLUDE_NO_WINAPI_H in the Preprocessor Defines box on the Compile/Link tab of the Settings dialog box.)

See Also