Pass multiple parameters to a .DLL - Advanced Installer Community
Dean.Wilson
Posts: 6
Joined: Mon Aug 22, 2011 10:17 am

Pass multiple parameters to a .DLL

Hi there,

I have a "New Installed Custom Action" custom action which points to CustomActions.CS.dll and calls the specified function no problem.

However I want to pass 2 parameters to the function. I tried

/ORIGINALFILE="[#Web.config_1]" /REPLACEFILE="[ConfigFiles_Dir]Providers.config"

trying to get it to pass in OriginalFile and ReplaceFile as separate parameters but it evaluated the entire line and passed it all in as one parameter i.e.

"C:\Program Files (x86)\Company\AppName\Application\Web.config" /REPLACEFILE="C:\Users\Me\Desktop\CustomerPackage\ConfigFiles\Providers.config"

How can I get it do recognise 2 separate parameters? I would prefer not to have to split it up in the code.

Thanks
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Pass multiple parameters to a .DLL

Hi,

DLL custom actions can receive installation information in multiple ways:
- if it's a win32 DLL which receives the installation handle, you can use MsiGetProperty function to read a property
- if it's a .NET Installer class you can set custom parameters for it
- if you use a Call function from a standard DLL custom action you can set the function arguments

I'm not sure how you are setting your parameters. Can you please give me more details?

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dean.Wilson
Posts: 6
Joined: Mon Aug 22, 2011 10:17 am

Re: Pass multiple parameters to a .DLL

There seems to be about 4 different ways to call a method on a .DLL, yet the way I described pointing to a file that gets installed in APPDIR seems to be the only one that doesn't either fail or simply not call the DLL.

I feel like I have tried every combination of different methods of calling a .dll with different methods of passing parameters but the above is the only one that comes close to working.

I want to call a .NET assembly .dll, calling a specific function, passing 2 strings. I do not want the CustomAction.dll to remain anywhere on the target machine.

Currently I do not understand:
1) Should the method in the .NET code accept a single Session parameter and get parameters from session.CustomActionData, or should I accept 2 strings as normal?
2) Should I use a New Attached Custom Action, and if so what goes in the Action Data to pass 2 strings as parameters?
3) ShouldI use a New Installed Custom Action, and if so what goes in the Action Data?
4) Using Call Function from Standard DLL did not seem to do anything. I had the code in the TempFolder and referenced it from there, and passed in the 2 parameters, and tried the code accepting just a session parameter, and then 2 separate string parameters, neither worked.
5) If I need to call a .NET installer class, what goes in the Action Data to pass in 2 string parameters, and when the guide says the code must inherit the "Installer" class, where is this class as I found a static Microsoft.Deployment.WindowsInstaller.Installer class and also a non-static System.Configuration.Install.Installer class. Also where do I set the RunInstaller attribute to true?
6) How can I make sure the CustomAction.dll file does not remain on the system (ideally using temp folder, or removing after?)

7) Also I suspect the next thing I will need to do is run a custom action on a file that the user selects in the UI. Can this be done and if so how? Again ideally making sure the file does not remain.

Hope thats enough info.
Thanks
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Pass multiple parameters to a .DLL

Hi,
Should the method in the .NET code accept a single Session parameter and get parameters from session.CustomActionData, or should I accept 2 strings as normal?
From your post I think converting your DLL to a .NET Installer class action would be the best approach.

For an installer class action you can set parameters which can be retrieved from Context.Parameters inside the action code. This works only when adding a ".NET Installer Class Action" custom action in your project. It doesn't work for any .NET DLL.

If you want to use an installer class action, you can find a tutorial here:
http://devcity.net/Articles/339/1/article.aspx

Please note that an installer class action can use only installed files. So the DLL will need to be installed on the target machine. If you really want to remove it, you can make sure that it's component is not registered with Windows Installer. This way you can use a simple custom action which deletes it when installation finishes.

The installer session can be used only in DLL custom actions that can receive the installation handle. Usually only win32 DLL or VBScript actions. So using CustomActionData property or ActionData field won't work the way you want.

If you want to use the installer session, you can try creating a C++ DLL custom action. In this case you can use an Attached custom action so you won't need to install the file.
Should I use a New Attached Custom Action
No. This type of custom action supports only Win32 DLLs and VBScript files.
ShouldI use a New Installed Custom Action
No. It has the same limitation as an Attached action.
If I need to call a .NET installer class, what goes in the Action Data to pass in 2 string parametersameters
This type of custom action pre-populates Action data with it's required parameters. You can also add your own custom parameters which can then be accessed from within your code.
when the guide says the code must inherit the "Installer" class, where is this class
It's "System.Configuration.Install.Installer" class. The tutorial I mentioned should explain everything you need to know about installer class actions.
How can I make sure the CustomAction.dll file does not remain on the system
For an installer class you will have to remove it after installation, for example through another custom action.
Also I suspect the next thing I will need to do is run a custom action on a file that the user selects in the UI.
This is not supported by Windows Installer or Advanced Installer. You would have to write your own custom action which gets the file path and calls functions from the target file.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
dmeatte
Posts: 4
Joined: Tue Jan 10, 2012 4:38 pm

Re: Pass multiple parameters to a .DLL

Dean.Wilson wrote:Hi there,

I have a "New Installed Custom Action" custom action which points to CustomActions.CS.dll and calls the specified function no problem.

However I want to pass 2 parameters to the function. I tried

/ORIGINALFILE="[#Web.config_1]" /REPLACEFILE="[ConfigFiles_Dir]Providers.config"

trying to get it to pass in OriginalFile and ReplaceFile as separate parameters but it evaluated the entire line and passed it all in as one parameter i.e.

"C:\Program Files (x86)\Company\AppName\Application\Web.config" /REPLACEFILE="C:\Users\Me\Desktop\CustomerPackage\ConfigFiles\Providers.config"

How can I get it do recognise 2 separate parameters? I would prefer not to have to split it up in the code.

Thanks
I was able to get multiple parameters passed into a .net wix dll with "param1=value;param2=value" (accessed in Session.CustomActionData). The wix custom action isn't a c++ dll, but I think it uses the same gui to set it up in advanced installer so hopefully it'll work for you.
chrisp
Posts: 1
Joined: Mon Sep 16, 2013 2:41 pm

Re: Pass multiple parameters to a .DLL

I've tried the following, and all result in the whole string being passed to the custom action as one single string:
/param1="x" /param2="y"
/param1=x param2=y
param1="x";param2="y"
param1=x;param2=y

So what is the correct format to be able to access each parameter individually from the custom action?
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Pass multiple parameters to a .DLL

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.

If you are using a WIX C# custom action, then you can pass your parameters (in the "Action Data" field) to your custom action like this:

Code: Select all

param1=value1;param2=value2
Also, you can access the parameters (from your custom action code) like this:
  • string parameter1 = session.CustomActionData["param1"];
    string parameter2 = session.CustomActionData["param2"];
For example, if you want to pass two properties value (e.g. PROP1 and PROP2) to a WIX C# custom action you can proceed like this:
- using Microsoft Visual Studio you should create a “WiX” -> “C# Custom Action Project”
- add the following rows to your custom action code:
  • string parameter1 = session.CustomActionData["param1"];
    string parameter2 = session.CustomActionData["param2"];
- open your Advanced Installer project, go to "Custom Actions" page and add a "Call function from attached native DLL" custom action like this:
  • Attached DLL: Ptah_to_CustomAction.CA.dll
    Function: CustomActionFunction
    Action Data: param1=[PROP1];param2=[PROP2]
- build and run your project

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”