0
votes

I have a c++ Custom action function as given below. This function is for retriving the Ini section from an INi file.

extern "C" LPSTR PASCAL EXPORT ReadFile(LPSTR IniFilename, LPSTR IniFIleSection, LPSTR IniKey, LPSTR DefaultValue)
{

    static char MyValue[512];
    sprintf(sValue, "%s %s %s %s",IniFilename, IniFIleSection, IniKey, DefaultValue);
    GetPrivateProfileString(IniFIleSection, IniKey, DefaultValue, MyValue, 512,IniFilename);
    return (sValue);

}

And i am using the Wix defenition for Customaction as given below

 <Binary Id="CustomCallId" SourceFile="CustomDllname.dll"  />
 <CustomAction Id="ReadValue" BinaryKey="CustomCallId" DllEntry="ReadFile"/>

 <InstallExecuteSequence>
  <Custom Action="ReadValue" Sequence="71" />
</InstallExecuteSequence>

But i am not sure how to pass the parameter from WIX Custom call to DLL.

2

2 Answers

2
votes

Windows Installer does not support this. It can only call functions from a C++ DLL with the prototype UINT __stdcall CustomAction(MSIHANDLE hInstall). Then the implementation of the function can use the MSIHANDLE to access properties from the active install.

If you control the code in this DLL, you can export a helper function that reads properties and then calls your original ReadValue function. Alternately you can look into other ways to wrap that call.

0
votes

This type of custom action should ideally be data driven. Here's the concept in C#. It's basically the same for C++. In fact, MichaelU (InstallShield) kindly enough translated my C# code into C++ code.

http://blog.deploymentengineering.com/2008/05/data-driven-cas-made-easy-with-dtf.html

You'd want to define a table like:

[INISearcher] INISearcher (primary key for uniqueness) FileName [type formatted to be able to use properties] Section Key DefaultData Property_

Your CA could would query this table, iterate the results, format the FileName and perform the INI read and then store the result in the Property listed in the table.