C ++自定义操作返回空字符串 [英] C++ Custom Action returns empty string

查看:152
本文介绍了C ++自定义操作返回空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在c ++中有一个延迟自定义操作的问题。我们只需要一个customactiondata属性apacheconfpath的值,此时有一个虚拟值test。

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.

这是一个我们的c ++自定义操作:

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);
}

此属性在我们的wix安装程序中设置:

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>

我添加了大量日志记录以尝试查看发生了什么。看来,属性永远不会被读取,因为dword值始终为0,并且数据始终为空。

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.

根据日志设置的值

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

推荐答案

当延迟自定义操作通过已知标识符 CustomActionData 请求数据时,您可以在此行末尾的日志文件中看到该名称:

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;)

要访问数据,您可以更改 MsiGetProperty 调用, p>

To access the data, you'd change your MsiGetProperty call to look more like:

MsiGetProperty(hInstall, TEXT("CustomActionData"), TEXT(""), &dActionDataLen);

注意:由于您已经在使用wcautil,我强烈建议使用 WcaGetProperty )而不是 MsiGetProperty()。您将需要检查 WcaGetProperty()的返回代码,这样,您的自定义操作将正确处理用户取消。否则,您的自定义操作可能会导致用户尝试取消安装。

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.

这篇关于C ++自定义操作返回空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆