securigydev
Posts: 2
Joined: Thu Oct 27, 2022 11:27 pm

Custom Action DLL

I followed the guide and created Custom Action DLL using Wix Toolset 4.
and it looks like that:

Code: Select all

       public static ActionResult VerifyLicense(Session session)
        {
            session.Log("Begin CustomAction1");

            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, args) => {
                return Assembly.ReflectionOnlyLoad(args.Name);
            };

            string licKey = session["LICKEY"];
            session.Log(licKey);

            string msg = CheckLicense(licKey).Result;

            session["SHOW_LIC_MSG"] = "1";
            session["LIC_VALIDATION_MSG"] = msg;

            session.Log(msg);
            MessageBox.Show(String.Format($"{msg}"), "Open Workspace", MessageBoxButtons.OK);

            if (msg.IndexOf("Success:", 0, StringComparison.OrdinalIgnoreCase) != -1)
            {
                session["ENABLE_NEXT"] = "1"; // A new property to control enabling the Next button
                session.Log("Next button is enabled");
                string ret = session["ENABLE_NEXT"];
                MessageBox.Show(String.Format($"ENABLE_NEXT: {ret}"));
            }
            else
            {
                session["ENABLE_NEXT"] = "0"; // A new property to control enabling the Next button
            }

            return ActionResult.Success;
        }
I created new LicDialog where user enters the license, and it has Validate button that triggers custom action via Published Event. The custom action executes just fine. However, I am unable to control the Enable/Disable state of the Next button on the dialog.
session["ENABLE_NEXT"] = "1"; This code does nothing to the button which is initially disabled. If custom action fails, the button should remain disabled and if it succeeds it should get enabled.

Also to mention that Next button has Control Conditions:
ENABLE_NEXT = "1" Action: Enable

The custom action is not sequenced action "Call function from attached native DLL". I assume that all the actions are immediate since there are no controls that allow me to enable/disable "immediate" thing.

What am I doing wrong and why is it not working?
Catalin
Posts: 7513
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action DLL

Hello,

In order to achieve what you want, you can proceed as it follows:

- in the custom action, set a property (e.g. ENABLE_BUTTON), e.g.:

if the validation is ok, set the ENABLE_BUTTON property to "1"

Note: Get and set a property in a DTF C# custom action

- we can then use this property to have two "Control Conditions" for our "Next" button (i.e. go to "Dialogs" page --> select your dialog --> click on the "Next" button --> click "Control Conditions")

- one control condition to disable the button and one to enable it. Or, for instance, you could have it disabled by default and only enable it if the validation from the custom action is correct.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”