如何在wix中将参数传递给自定义操作方法

时间:2012-11-14 05:44:21

标签: wix parameter-passing custom-action wix3.6

我是新手使用wix工具创建MSI安装程序,在这里我有一个查询请帮我解决这个问题。   我的查询是:我已经创建了一个自定义UI,在这个我有一个组合框控件,我已经动态使用自定义Action方法绑定组合框值,它工作正常。现在,我想将参数(组合框选择值)传递给自定义动作方法,我不知道如何传递参数。我戴上了眼镜,但我没有得到答案,请帮助我。

这是我的代码

 <Binary Id="CustomActions" SourceFile="D:\WIX Projects\ExampleSetup\CustomAction1\bin\Debug\CustomAction1.CA.dll" />
<CustomAction Id='Action1' BinaryKey='CustomActions' DllEntry='FillServerInstances' Execute='immediate' Return='check' />
<UI>
  <Dialog Id="CustomWelcomeEulaDlg" Width="600" Height="450" Title="!(loc.WelcomeEulaDlg_Title)">
    <Control Id="Bitmap" Type="Bitmap" X="0" Y="44" Width="600" Height="380" TabSkip="no" Text="MainImage" />
    <Control Id="Next" Type="PushButton" X="290" Y="430" Width="60" Height="17" Default="yes" Text="Next">
      <Publish Event="DoAction" Value="Action1">1</Publish>
      <Publish Event="NewDialog" Value="LicenseAgreementDlgs"><![CDATA[1]]></Publish>
      <Publish Event="ReinstallMode" Value="ecmus"><![CDATA[Installed = 1]]></Publish>
    </Control>
    <Control Id="Cancel" Type="PushButton" X="350" Y="430" Width="56" Height="17" Cancel="yes" Text="Cancel">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
    <Control Id="Title" Type="Text" X="15" Y="6" Width="300" Height="15" Transparent="yes" NoPrefix="yes">
      <Text>[DlgTitleFont]Welcome to the [ProductName] [Wizard]</Text>
    </Control>
    <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="600" Height="0" />
   </Dialog>

最新代码

 <Product Id="22d32870-651b-4eee-a622-27b2daaade8c" Name="Small Business" Language="1033" Version="1.0.0.0" Manufacturer="Small Business Manufacturing" UpgradeCode="01b2dc2f-61f3-4ff0-a0ba-94dd4cb0829d">

      <Package InstallerVersion="200" Compressed="yes" />

      <Property Id="MSIFASTINSTALL" Value="3" />
        <Binary Id="BIN_CustomAction" SourceFile="D:\WIX Projects\ExampleSetup\CustomAction1\bin\Debug\CustomAction1.CA.dll"/>
        <Binary Id="myAction" SourceFile="D:\WIX Projects\ExampleSetup\CustomAction1\bin\Debug\CustomAction1.CA.dll"/>
       <UIRef Id="WixUI_CustomMinimal" />

        <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
         <Property Id="FILEPATH" />
                 <Directory Id="TARGETDIR" Name="SourceDir">
                 <Directory Id="ProgramFilesFolder">
                 <Directory Id="INSTALLLOCATION" Name="Small Business Manufacturing">
                   <Component Id="Component" Guid="af10d5b4-5d25-474f-8360-13b6c0cd7a53">
                    <File Id="Component" Source="D:\WIX Projects\Small Business Manufacturing\Small Business Manufacturing\bin\Debug\Myproject.exe" Compressed="yes" KeyPath="yes" Checksum="yes" />
                    </Component>

             </Directory>
             </Directory>
            </Directory>

                 <Feature Id="ProductFeature" Title="Installation Target" Level="1">
               <ComponentRef Id="Component" />
                </Feature>
                   <InstallExecuteSequence>
                  <Custom Action="myActionId" After="InstallFinalize"></Custom>
                  </InstallExecuteSequence>
              <CustomAction Id="SetCustomActionDataValue" Return="check" Property="myActionId" Value="AnotherValue=[Sqlinstaces]" />
        <UI>
          <ProgressText Action="RunEXE">Configuring Foo... (this may take a few minutes).</ProgressText>
        </UI>

      </Product>

1 个答案:

答案 0 :(得分:2)

据我所知,您无法将参数传递给自定义操作。您可以在Wix中设置属性,并使用WcaGetProperty来访问该属性。

我使用类似的列表框:

<!--This will be populated via the custom action-->
    <Control Id="ListBoxID" Type="ListBox" Property="COMPORT" Width="80" Height="40" X="80" Y="165" Indirect="no">
      <ListBox Property="COMPORT">
      </ListBox>
    </Control>

在我的C ++自定义操作中:

hr = WcaGetFormattedProperty(L"COMPORT",&szComport);
ExitOnFailure(hr, "failed to get Com Port");

编辑:

好的,所以我假设您的ComboBox是这样的:

  <Control Id="DummyComboBox" Hidden="yes" Type="ComboBox" Sorted="yes" ComboList="yes" Property="DUMMYPROPERTY" X="65" Y="60" Width="150" Height="18">
  <ComboBox Property="DUMMYPROPERTY">
  </ComboBox>

确保您的财产定义如下(确保大写字母):

    <Property Id="DUMMYPROPERTY" Secure="yes"></Property>

您不需要自定义操作来发送属性的值。您所要做的就是使用:

LPWSTR dummyText = NULL;

hr = WcaGetProperty(L"DUMMYPROPERTY", &dummyText);
ExitOnFailure(hr, "failed to get Dummy Text");

这对于C ++自定义操作不确定您使用的是什么,但快速谷歌搜索会告诉您要使用的相关代码。