| InstallerContactSite Map |
Advanced Installer User Guide | |||
Developing a DLL for serial number validation |
| To validate a serial number during installation, you need to provide a DLL with a function that checks the serial entered by the user. This DLL will run as a custom action. The scenario used to validate the serial number is as following. If your package is run at full UI level the validation starts when the user presses the button from the “User Registration” dialog.
If your package is not run with full UI Level,the validation is triggered at the beginning of the installation sequence:
Below is presented a C++ skeleton code to guide you into writing your own DLL for serial number validation.
UINT __stdcall ValidateSerial_Sample(MSIHANDLE hInstall)
{
TCHAR szPidKey[PIDKEY_LENGTH];
DWORD dwLen = sizeof(szPidKey)/sizeof(szPidKey[0]);
//retrive the text entered by the user
UINT res = MsiGetProperty(hInstall, _T("PIDKEY"), szPidKey, &dwLen);
if(res != ERROR_SUCCESS)
{
//fail the installation
return 1;
}
bool snIsValid = false;
//validate the text from szPidKey according to your algorithm
//put the result in snIsValid
TCHAR * serialValid;
if(snIsValid)
serialValid = _T("TRUE");
else
{
//eventually say something to the user
MessageBox(0, _T("Invalid Serial Number"), _T("Message"), MB_ICONSTOP);
serialValid = _T("FALSE");
}
res = MsiSetProperty(hInstall, _T("SERIAL_VALIDATION"), serialValid);
if(res != ERROR_SUCCESS)
{
return 1;
}
//the validation succeeded - even the serial is wrong
//if the SERIAL_VALIDATION was set to FALSE the installation
//willl not continue
return 0;
}Sample CodeFor an easy way to develop your own validation DLL, download and unzip the Serial Number Validation DLL Sample Project. It contains a fully functional Visual Studio .NET project which creates a C++ DLL doing a trivial validation, together with an Advanced Installer project which uses the DLL.
|
