问题
We are having problem with a deferred custom action in c++. We simply want the value for a customactiondata property 'apacheconfpath' which has a dummy value of test at the moment.
Here is a our c++ custom action:
UINT __stdcall AppendToApacheConfigFile(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
TCHAR sWord[100];
hr = WcaInitialize(hInstall, "AppendToApacheConfigFile");
ExitOnFailure(hr, "Failed to initialize");
TCHAR szActionData[MAX_PATH] = {0};
DWORD dActionDataLen = MAX_PATH;
MsiGetProperty (hInstall, TEXT("apacheconfpath"), TEXT(""), &dActionDataLen);
StringCbPrintf(sWord, 100, TEXT("%d"), dActionDataLen);
WcaLog(LOGMSG_STANDARD, "dActionDataLen = %s", sWord);
if (dActionDataLen > 0)
{
++dActionDataLen;
StringCbPrintf(sWord, 100, TEXT("%d"), dActionDataLen);
WcaLog(LOGMSG_STANDARD, "dActionDataLen(2) = %s", sWord);
MsiGetProperty (hInstall, TEXT("apacheconfpath"), szActionData, &dActionDataLen);
WcaLog(LOGMSG_STANDARD, "szActionData = %s", szActionData);
StringCbPrintf(sWord, 100, TEXT("%d"), dActionDataLen);
WcaLog(LOGMSG_STANDARD, "dActionDataLen(3) = %s", sWord);
//Do something with the value
}
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}
The property is set here in our wix installer:
<CustomAction Id="AppendToApacheConfigFile_Cmd" Property="AppendToApacheConfigFile" Value="/apacheconfpath=test;" />
<CustomAction Id="AppendToApacheConfigFile" BinaryKey="CustomActionDll" DllEntry="AppendToApacheConfigFile" Execute="deferred" />
<InstallExecuteSequence>
<Custom Action="AppendToApacheConfigFile_Cmd" Before="AppendToApacheConfigFile"><![CDATA[IIS_SELECTED <> 1]]></Custom>
<Custom Action="AppendToApacheConfigFile" After="DeployPhpRuntime"><![CDATA[IIS_SELECTED <> 1]]></Custom>
</InstallExecuteSequence>
I have added lots of logging to try to see what is happening. It would appear that the property is never read as the dword value is always 0 and the data is always empty. We never get past the first read.
According to the log the value has been set
MSI (s) (80:C4) [20:59:30:210]: Executing op: CustomActionSchedule(Action=AppendToApacheConfigFile,ActionType=1025,Source=BinaryData,Target=AppendToApacheConfigFile,CustomActionData=/apacheconfpath=test;)
Any information would be most welcome
回答1:
When the deferred custom action requests the data it ask for it via the well known identifier CustomActionData
. You can see that name referenced in the log file at the end of this line:
MSI (s) (80:C4) [20:59:30:210]: Executing op: CustomActionSchedule(Action=AppendToApacheConfigFile,ActionType=1025,Source=BinaryData,Target=AppendToApacheConfigFile,CustomActionData=/apacheconfpath=test;)
To access the data, you'd change your MsiGetProperty
call to look more like:
MsiGetProperty(hInstall, TEXT("CustomActionData"), TEXT(""), &dActionDataLen);
Note: Since you are already using wcautil, I highly recommend using WcaGetProperty()
instead of MsiGetProperty()
. You'll want to check the return code from WcaGetProperty()
and in doing so your custom action will correctly handle user cancels. Otherwise, your custom action could swallow the user's attempt to cancel the install.
来源:https://stackoverflow.com/questions/16135732/c-custom-action-returns-empty-string