Search code examples
wixcustom-action

How to call a function from a DLL?


Can I call a function from a DLL (custom action) to search for the location a program is already installed on and install my msi there?


Solution

  • You don't need a custom action in this case. Use DirectorySearch / FileSearch elements WiX provides out of the box. Besides, if that program leaves a trace in system registry, RegistrySearch element is useful.

    UPDATE: As far as I understand from your comments below, you have the ready-made function for detecting the path the main program was installed to, and you'd like to utilize this functionality to install extra add on there.

    You should author an immediate custom action (CA) which calls a function from a DLL and schedule it somewhere between AppSearch and LaunchConditions. This custom action should save the result into an MSI property, for example, INSTALLLOCATION. This means if you have a function which returns a path, you might want to wrap it into another function (the actual CA) which will just save that value to INSTALLLOCATION property.

    You can then use this property in your directory structure like this:

      <Directory Id="TARGETDIR" Name="SourceDir">
         <Directory Id="INSTALLLOCATION" Name="my app">
         ...
         </Directory>
      </Directory>
    

    NOTE: Following this advice still requires some basic knowledge about Windows Installer and WiX, so I strongly recommend you to address MSDN and WiX tutorial for basics.