Revenera logo

Just as sometimes you want to let your users configure the software, sometimes you need to limit the choices they can make. Maybe you’re checking if they’re up too late by asking them to solve a trivial arithmetic problem. Or maybe it’s a matter of allowing them to continue only if they have a valid serial number. In this article, I’ll show how to do the first in a custom wizard page, using a custom DLL I create with Microsoft Visual C++ 2010 Express.

Similar to last time, I start by creating a new project called SuiteCalc, in which I select an application type of DLL, change my Runtime Library to /MT and /MTd, and add a module definition file named SuiteCalc.def to export the function VerifySum and wire the file to my Linker Input properties. This function follows the interface Hidenori described in his Calling a Function in a DLL from a Wizard Page or Window in a Suite Installation blog post, and it can be called by specifying it in either an Action or a Validate setting of any supporting control. The settings Action and Validate differ in that Validate runs the function before changing the property (calls to get_Property retrieve the old value of the property), and a failure return value prevents the change from being committed; Action runs the function after the change is committed, and a failure return value indicates the install should abort. So I create the function VerifySum in SuiteCalc.cpp.

HRESULT __stdcall VerifySum(IDispatch *pDispatch);

InstallShield icon

InstallShield

Create native MSIX packages, build clean installs, and build installations in the cloud with InstallShield from Revenera.

The function VerifySum reads three properties, checks the math, and stores a result into a fourth property. For simplicity it will always read Addend1 and Addend2, and compare their sum to Sum. When all three are supplied, it will set Correct to either Yes or No, and when there isn’t a valid mathematical equation because one of the properties doesn’t hold a number, it will set Correct to an empty string.

Next I create a Suite project, add a test package, and add SuiteCalc.dll to the project through the Support Files view. It’s time to modify the wizard. The InstallationWelcome page needs a way to specify Addend1, Addend2, and Sum, so I add three new text box controls, and set their properties. Each of those text boxes will have their Action setting set to {SuiteCalc::VerifySum} in order to invoke the validation. To react to the results of this action, there are a couple options. One is to add a label with its Property set to Correct, and another is to add two labels with text like Correct and Wrong with their visible conditions set to {Binding Correct==Yes} and {Binding Correct=No} respectively. I’ll go with the second. Finally to prevent installing when I can’t add numbers correctly, I set the Next button’s enabled condition to {Binding Correct==Yes}. For completeness, I added a label with a plus and an equal sign between the text boxes.

And that’s it: we have our calculator. The attached SuiteCalc.zip file contains the sample source code I’ve described, as well as a built DLL and a project that uses it. You can use the same approach to check anything you’d like. You could even make a web call. Just beware that the longer the code takes to execute, the longer the end user has to wait to see the results.

Note that actions that call a function in a DLL require InstallShield 2012 SP1. To obtain SP1, see Q201298: InstallShield 2012 Service Pack 1. For information about the InstallShield 2012 release, see the InstallShield 2012 demo.