Getting CustomActionData from C++

2019-09-08 17:32发布

问题:

I have a Wix file where I am creating a Deferred Custom Action. I have written a C# program, which is, for now, looping over the CustomActionData and printing the Key and Values. Consider the snippet given below:

<Binary Id="myAction" SourceFile="..\Type51CA\bin\Release\Type51CA.CA.dll" />
<CustomAction Id="CustomAction1" Property="CustomAction2" Value="SomePropertyOne=[INSTALLFOLDER];SomePropertyTwo=[IPADDRESS];" />
  <CustomAction Id="CustomAction2" BinaryKey="myAction" DllEntry="MyCustomAction" Execute="deferred" Return="check" HideTarget="no" />
<InstallExecuteSequence>
   <Custom Action="CustomAction1" Before="CustomAction2" />
   <Custom Action="CustomAction2" Before="InstallFinalize" />
</InstallExecuteSequence>

I am setting the SomePropertyOne and SomePropertyTwo in CA Id="CustomAction1".

The following C# code can iterate over CustomActionData

session.Log("Begin MyCustomAction");
CustomActionData datas = session.CustomActionData;
foreach (KeyValuePair<String, String> data in datas)
{
   session.Log(String.Format("Key = {0} Value = {1}\n", data.Key, data.Value));
}

Since I want to remove the dependency of .Net, I want to write the equivalent C# code in C++; using WcaGetProperty(L"CustomActionData",&caData) didn't give me any result. In C++, how can I get the required value of a corresponding Key from CustomActionData?

回答1:

CustomActionData can be as simple as you want or as complicated as you want. My favorite is JSON but in reality it doesn't really matter as long as the CA setting the property and the CA decoding the property follow the same spec.