using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Diagnostics; using System.Runtime.InteropServices; namespace Validation { public class Class1 { // The kLibraryKey is meant to prevent unauthorized use of the library. // Do not share this key. Replace this key with your own from Advanced Installer // project > Licensing > Registration > Library Key private const string kLibraryKey = "3C770255172DB4CE6E38BFCDD0930341F7F22BC405A25E57DF01816FD99D287D3DCEE5C3F5E0"; public Class1() { // We launch the trial UI on a thread because we want the trial UI to be // displayed after you main application UI is displayed. Thread thread = new Thread(InitTrial); thread.Start(); } // Main trial function // This function does all the work // // @return // - 0 when licensed // - 2 when unlicensed but in trial [DllImport("Trial.dll", EntryPoint = "ReadSettingsStr", CharSet = CharSet.Ansi)] static extern uint InitTrial(String aKeyCode, IntPtr aHWnd); // This function does all the work but it will NOT kill the application // // @return // - 0 when licensed // - 2 when unlicensed but in trial // - values grater or equal with 4 when unlicensed and trial expired [DllImport("Trial.dll", EntryPoint = "ReadSettingsRetStr", CharSet = CharSet.Ansi)] static extern uint InitTrialReturn(String aKeyCode, IntPtr aHWnd); // Use this function to register the application using the provided serial [DllImport("Trial.dll", EntryPoint = "DisplayRegistrationStr", CharSet = CharSet.Ansi)] static extern uint DisplayRegistration(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 InitTrial() { try { // Wait 2 second for the main window to be visible. Thread.Sleep(2000); Debug.WriteLine("Debug Information-Product Starting "); Process process = Process.GetCurrentProcess(); InitTrial(kLibraryKey, process.MainWindowHandle); // To prevent your application be killed when unlicensed and trial expired // ReadSettingsRetStr must be called which will return 4 or grater instead of killing the app // // uint ret = InitTrialReturn(kLibraryKey, process.MainWindowHandle); // // if (ret >= 4) // { // MessageBox.Show("Invalid mode to run"); // // disable the application // // Process.GetCurrentProcess().Kill(); // } // Let's read some licensing configuration property StringBuilder trialName = new StringBuilder(); UInt32 len = (UInt32)trialName.Capacity; if (GetPropertyValue("TrialName", trialName, ref len) == 234) { trialName.EnsureCapacity((Int32)len); GetPropertyValue("TrialName", trialName, ref len); } Debug.WriteLine("TrialName=" + trialName); } catch (DllNotFoundException ex) { // Trial dll is missing close the application immediately. //MessageBox.Show(ex.ToString()); Process.GetCurrentProcess().Kill(); } catch (Exception ex1) { //MessageBox.Show(ex1.ToString()); } } } }