09.12.2012 Views

InstallShield 2012 Spring Express Edition User Guide

InstallShield 2012 Spring Express Edition User Guide

InstallShield 2012 Spring Express Edition User Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10: Customizing Installation Behavior<br />

Using Custom Actions<br />

<strong>Edition</strong>: The Premier and Professional editions of <strong>InstallShield</strong> include support for several custom action types that are not<br />

available in the <strong>Express</strong> edition. These extra custom action types enable you to do the following: run InstallScript code, set<br />

a property, set a directory, call a public method in a managed assembly, or display an error message under certain<br />

conditions and abort the installation.<br />

Windows Installer DLL Custom Actions<br />

If you need to perform an action in your installation that is not natively supported by <strong>InstallShield</strong> or the<br />

Windows Installer service, you can create a custom action that calls an entry-point function from a<br />

Windows Installer .dll file. With this type of custom action, often called an MSI DLL action, the function<br />

must be defined with the following signature:<br />

UINT __stdcall FunctionName (MSIHANDLE hInstall) {...}<br />

The function name can vary; however, the return type, calling convention, and single parameter must<br />

use the types that are specified in the aforementioned signature. The MSIHANDLE data type that is used<br />

in the function signature is a handle to the running installation.<br />

The following sample code is for a function called MyFunctionName.<br />

UINT __stdcall MyFunctionName (MSIHANDLE hInstall)<br />

{<br />

MessageBox(<br />

GetForegroundWindow( ),<br />

TEXT("This is MyFunctionName."),<br />

TEXT("Custom Action"),<br />

MB_OK | MB_ICONINFORMATION);<br />

return ERROR_SUCCESS;<br />

}<br />

Your entry-point function should return ERROR_SUCCESS to indicate that the action finished<br />

successfully. If your custom action returns a non-zero value and you selected No for the custom action’s<br />

Ignore Exit Code setting, the installation exits. If you selected Yes for the custom action’s Ignore Exit<br />

Code setting, the installation continues, regardless of the custom action’s return code.<br />

Once your MSI DLL is ready, you must design a custom action to call the entry-point function. To learn<br />

how to create the custom action, see Adding an MSI DLL Custom Action to Your Project.<br />

Requirements<br />

• Header: Declared in Msiquery.h<br />

• Library: Use Msi.lib<br />

Both Msiquery.h and Msi.lib can be found in the Windows Installer SDK, which can be downloaded<br />

from Microsoft’s Web site. In addition to the two files listed above, the Windows Installer SDK contains<br />

Microsoft’s definitive documentation on the Windows Installer APIs.<br />

<strong>InstallShield</strong> <strong>2012</strong> <strong>Spring</strong> <strong>Express</strong> <strong>Edition</strong> <strong>User</strong> <strong>Guide</strong> ISE-1900-UG00 223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!