C自定义操作返回空字符串
作者:互联网
我们对c中的延迟自定义操作有疑问.我们只是想要有一个虚拟测试值的customactiondata属性“ apacheconfpath”的值.
这是我们的c自定义操作:
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);
}
该属性在我们的wix安装程序中设置:
<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>
我添加了许多日志记录以尝试查看正在发生的情况.似乎永远不会读取该属性,因为dword值始终为0,数据始终为空.我们永远都不会错过一读.
根据日志值已设置
MSI (s) (80:C4) [20:59:30:210]: Executing op: CustomActionSchedule(Action=AppendToApacheConfigFile,ActionType=1025,Source=BinaryData,Target=AppendToApacheConfigFile,CustomActionData=/apacheconfpath=test;)
任何信息将是最欢迎的
解决方法:
当延迟的自定义操作请求数据时,它将通过众所周知的标识符CustomActionData来请求它.您可以在此行末尾的日志文件中看到该名称:
MSI (s) (80:C4) [20:59:30:210]: Executing op: CustomActionSchedule(Action=AppendToApacheConfigFile,ActionType=1025,Source=BinaryData,Target=AppendToApacheConfigFile,CustomActionData=/apacheconfpath=test;)
要访问数据,您可以将MsiGetProperty调用更改为如下所示:
MsiGetProperty(hInstall, TEXT("CustomActionData"), TEXT(""), &dActionDataLen);
注意:由于您已经在使用wcautil,因此我强烈建议您使用WcaGetProperty()而不是MsiGetProperty().您将要检查WcaGetProperty()的返回码,并在这样做时,您的自定义操作将正确处理用户取消.否则,您的自定义操作可能会吞噬用户取消安装的尝试.