Using licensing with in built dialog force closing the app - Advanced Installer Community
bhavinjo
Posts: 7
Joined: Wed Sep 18, 2013 3:22 am

Using licensing with in built dialog force closing the app

I want to use the in built licensing dialogues but the problem is, if I set the display frequency to anything > 0 for e.g. 1, even when the product is in trial, the trial dialog box still shows up after running the app just once saying 29 runs left for example for a 30 day trial. Upon hitting cancel on it, the application just quits. Since its still in trial, it should not kill the app upon hitting cancel.

The problem is after running the app only once, return code is 5 although its still in trial.

I have followed the code from tutorial example as below

Code: Select all

private const string kLibraryKey = "actualKey";

      [DllImport("Trial.dll", EntryPoint = "ReadSettingsRetStr", CharSet = CharSet.Ansi)]
      static extern uint InitTrialReturn(String aKeyCode, IntPtr aHWnd);

      private static void checkRegistrationStatus()
      {         
         try
         {
            Process process = Process.GetCurrentProcess();
            uint retCode = InitTrialReturn(kLibraryKey, process.MainWindowHandle);

            if (retCode >= 4)
            {
               Process.GetCurrentProcess().Kill();
            }
         }
         catch (DllNotFoundException exTrialDllNotFound)
         {            
            MessageBox.Show(exTrialDllNotFound.ToString());
            Process.GetCurrentProcess().Kill();
         }
         catch (Exception exCheckRegistrationStatus)
         {
            MessageBox.Show(exCheckRegistrationStatus.ToString());
            Process.GetCurrentProcess().Kill();
         }
      }
And then in main

Code: Select all

checkRegistrationStatus();
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Using licensing with in built dialog force closing the a

Hello,
if I set the display frequency to anything > 0 for e.g. 1, even when the product is in trial, the trial dialog box still shows up after running the app just once saying 29 runs left for example for a 30 day trial
This may happen when the “Both”(runs and days) trial method is chosen in the Options tab. For a second run in the installing day of the application this will be the right message because the smallest quantity is displayed(29 runs).
Upon hitting cancel on it, the application just quits. Since its still in trial, it should not kill the app upon hitting cancel.
Please keep in mind that in order to use the Trial mode of the application the user needs to press the [Try] button. When the [Try] button is pressed then is considered that you started the application.

This is our default behavior and I'm afraid there is no workaround.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
bhavinjo
Posts: 7
Joined: Wed Sep 18, 2013 3:22 am

Re: Using licensing with in built dialog force closing the a

Thanks for your reply Dan.

I changed it to only 3 uses for testing. The problem is after the 1st use, the registration dialog comes up saying 2 uses left but there are only 3 buttons on the dialog, back, next and cancel. On clicking cancel the application simply quits.

Also tried using code below to determine if the trial is still on

Code: Select all

private const string kLibraryKey = "actualKey";

		[DllImport("Trial.dll", EntryPoint = "ReadSettingsRetStr", CharSet = CharSet.Ansi)]
		static extern uint InitTrialReturn(String aKeyCode, IntPtr aHWnd);

		[DllImport("Trial.dll", EntryPoint = "GetPropertyValue", CharSet = CharSet.Unicode)]
		static extern uint GetPropertyValue(String aPropName, StringBuilder aResult, ref UInt32 aResultLen);

		private static void checkRegistrationStatus()
		{
			try
			{
				Process process = Process.GetCurrentProcess();
				uint returnCode = InitTrialReturn(kLibraryKey, process.MainWindowHandle);

				StringBuilder trialLeft = new StringBuilder();
				UInt32 lenValue = (UInt32)trialLeft.Capacity;
				if (GetPropertyValue("TrialLeft", trialLeft, ref lenValue) == 234)
				{
					trialLeft.EnsureCapacity((Int32)lenValue);
					GetPropertyValue("TrialLeft", trialLeft, ref lenValue);
				}

				MessageBox.Show(trialLeft.ToString());

				if (returnCode >= 4 && trialLeft.ToString() == "0")
				{
					Process.GetCurrentProcess().Kill();
				}			
			}
			catch (DllNotFoundException exTrialDllNotFound)
			{
				MessageBox.Show(exTrialDllNotFound.ToString());
				Process.GetCurrentProcess().Kill();
			}
			catch (Exception exCheckRegistrationStatus)
			{
				MessageBox.Show(exCheckRegistrationStatus.ToString());
				Process.GetCurrentProcess().Kill();
			}
		}
Problem is only for the first run of the application, trialLeft = 3, for the subsequent runs of the application, I get an empty string.

Please let me know what do I need to change to make it work.

Also it's a console application that I trying this with.

Thanks in advance.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Using licensing with in built dialog force closing the a

Hi,

This may happen if your application doesn't use a common controls manifest (Microsoft.Windows.Common-Controls version 6.0). In order to avoid this behavior you need to include a manifest which makes your application use Microsoft.Windows.Common-Controls version 6.0.
Please take a look on our Error in License module thread which debates this issue.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
bhavinjo
Posts: 7
Joined: Wed Sep 18, 2013 3:22 am

Re: Using licensing with in built dialog force closing the a

Thanks much Dan for pointing me in the right direction. That did it it for me.

You may now close this thread.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Using licensing with in built dialog force closing the a

You're welcome. If you have other questions, please let us know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”