Calling MessageBoxA in an Installation

InstallShield 2022

Project:This information applies to the following project types:

Basic MSI
InstallScript MSI

To call the Windows API function MessageBoxA() in a custom action to display a message box:

Part A: Launch the Custom Action Wizard

1. In the View List under Behavior and Logic, click Custom Actions and Sequences.
2. Right-click the Custom Actions explorer and click Custom Action Wizard.

Part B: Start a Custom Action

1. In the Basic Information panel, type CA_Example for the custom action’s name. Click Next.
2. In the Action Type panel, for the custom action’s type, select Call a function in a standard dynamic-link library.
3. Since MessageBoxA is exported in User32.dll, which is found on every supported Windows platform, select Destination machine search path in the Location list. Click Next to continue.

Part C: Provide the Function Definition

MessageBoxA() has the following syntax:

    int MessageBoxA (hWnd, lpText, lpCaption, uType);

 

Specify this information in the Function Definition panel:

1. In the Name box, type MessageBoxA.
2. Click the last row in the Arguments box to specify the first parameter. Edit the fields for each parameter until they mirror the following list:

Parameters for the Arguments Box

Type

Source

Value

HWND

Constant

MsiWindowHandle

STRING

in Property

MESSAGEPROP

STRING

in Property

CAPTIONPROP

NUMBER

Constant

1

In the Value list for the HWND type, select MsiWindowHandle. If you set the HWND type to this value, your message box will not hide behind the installation window. The properties MESSAGEPROP and CAPTIONPROP are not available in the list. When you enter these names in the Value list, they are added to the Property Manager.

3. In the Return Type list, select void. (Although MessageBoxA() does return a number, checking that value in a property is outside the scope of this example.)
4. Click Next to proceed to the Action Parameters panel.

Part D: Specify the Source for MessageBoxA

The next significant setting in the Custom Action Wizard is the Source field in the Action Parameters panel. MessageBoxA is found in User32.dll. Click the Browse button to locate User32.dll in your Windows system folder.

In the next panel of the wizard, click Next to accept the defaults, and then click Finish in the Summary panel to dismiss the wizard and add CA_Example to your project.

Part E: Initialize the Properties’ Values

For the string parameters in MessageBoxA(), properties were provided, as described in the above procedures. The next step is to give those properties a value:

1. In the View List under Behavior and Logic, click Property Manager to view the installer properties in your project. The properties MESSAGEPROP and CAPTIONPROP were created as a result of referencing these properties in the Custom Action Wizard.
2. Locate MESSAGEPROP and click in its Value column to supply a value. Enter Can you see this text? for the value.
3. Set the CAPTIONPROP property to Custom Action Example.

Part F: Insert the Custom Action into a Sequence

In order to execute the custom action, you must either place it into a sequence or make it the result of a dialog’s control event.

Follow the steps below to insert CA_Example into the Installation sequence of the installation project:

1. In the View List under Behavior and Logic, click Custom Actions and Sequences.
2. In the Sequences explorer, under the Installation sequence, expand the User Interface item. The actions and dialogs that are scheduled for this sequence are listed.
3. Right-click the MigrateFeatureStates action (the action right before the InstallWelcome dialog) and click Insert. The Insert Action dialog box opens.
4. In the list at the top of the dialog box, select Custom Actions (for installation projects).
5. In the list of custom actions, select CA_Example.
6. Click OK.

CA_Example is added to the Installation sequence directly after MigrateFeatureStates.

Part G: Test the Call to MessageBoxA

1. Build a release. (The Output window may show build errors if you have not added any components or files to your project.)
2. On the Build menu, click Run.

InstallShield runs your installation. After the Welcome dialog is displayed, a Custom Action Example message box opens.

See Also