Calling Functions in Windows Installer DLL Files

InstallShield 2016

Project • This information applies to the following project types:

Basic MSI
DIM
InstallScript MSI
Merge Module
MSI Database
MSM Database
Transform

A DLL file function specifically written for a Windows Installer custom action can accept only the handle to the installer database as a parameter. The steps below explain how you can retrieve information from the .msi database for use in your custom action.

You specify that your custom action resides in a Windows Installer DLL file (custom action types 1 and 17) by selecting Call a function in a Windows Installer dynamic-link library in the Custom Action Wizard’s Action Type panel.

An alternative is to select Call a function in a standard dynamic link library in the Action Type panel. In this case, InstallShield allows you to specify the function’s parameters.

There are three major steps involved in passing a parameter to a function in a DLL file written for Windows Installer:

1. Prepare your DLL file.
2. Create a custom action and insert it into one of the sequences.
3. Pass the parameter using the Property Manager view. These steps are explained in greater detail below.

Preparing DLL Files

In order for you to pass data to a DLL file function in a custom action, the function to which you are passing data needs to call the MsiGetProperty function, which retrieves the value of an installer property. In the example below, it retrieves the value of a public property called MYPROPERTY.

    UINT __stdcall MyActionName(MSIHANDLE hInstall)

    {

        TCHAR szValue[51] = {0};

        DWORD dwBuffer = 50;

    

        MsiGetProperty(hInstall, TEXT("MYPROPERTY"), szValue, &dwBuffer);

    

        MessageBox(GetForegroundWindow( ),

            szValue,

            TEXT("Value of MYPROPERTY"), MB_OK | MB_ICONINFORMATION);

    

        return ERROR_SUCCESS;

    }

For more information, see MsiGetProperty in the Windows Installer Help Library.

If you use a C++ compiler to build your DLL file, ensure that the compiler does not change the function names exported from the DLL file. With Microsoft Visual C++, for example, you can create a .def file that specifies the function names to be exported from your DLL file. A typical .def (called MyActions.def) file looks like the following:

LIBRARY MyActions

EXPORTS

    MyActionName

For more information about function name decoration, see your compiler documentation.

Creating Custom Actions and Inserting them into Sequences

The second step is to create your custom action and insert it into one of the Installation sequences. To create the custom action, use the Custom Action Wizard, and to place the custom action, use the Custom Actions and Sequences view.

Passing the Parameter Using the Property Manager

To pass the new parameter using the Property Manager:

1. In the View List under Behavior and Logic, click Property Manager.
2. Click the New Property button. InstallShield adds a new row at the bottom of the view.
3. In the Name column, type the name of the property that you would like to retrieve with MsiGetProperty (MYPROPERTY, in this example).
4. In the Value column, type the value that you want to pass. For example, if you want to pass the URL to your Web site, type http://www.mycompany.com.

See Also