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;
}
Das ganze wird als DLL in eine Windows Installer installation eingebaut (zum überprüfen einer Seriennummer), allerdings bricht der Installer immer beim Aufruf von MsiGetProperty ab...
Da ich nicht wirklich Ahnung von C++ habe hoffe ich mal das mir hier einer weiterhelfen kann
Procedure.l ValidateSerial_Sample(hInstall.l)
#PIDKEY_LENGTH = 256
szPidKey.s = Space(#PIDKEY_LENGTH)
dwLen = #PIDKEY_LENGTH
res = MsiGetProperty_(hInstall, "PIDKEY", szPidKey, @dwLen)
If res <> #ERROR_SUCCESS
ProcedureReturn 1
EndIf
snIsValid = #False
*serialValid.STRING
If snIsValid
*serialValid = @"TRUE"
Else
MessageBox_(0, "Invalid Serial Number", "Message", #MB_ICONSTOP)
*serialValid = @"FALSE"
EndIf
res = MsiSetProperty_(hInstall, "SERIAL_VALIDATION", *serialValid)
If res <> #ERROR_SUCCESS
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Was mich aber schon die ganze Zeit wundert, warum schreibt man zuerst "snIsValid = #False" und danach "If snIsValid" wenn das doch niemals eintreten kann ~_~