Answer:
The Advanced Licensing Support can be easily integrated with your managed application. In what follows it will be described how to achieve this in VB.NET and C#.
Step 1 - Loading and initializing the Licensing library.
The licensing support resource file consists of a Dynamic Load Library with the following exported functions.
- ReadSettingsStr - the DLL entry function that does the initialization and validation of the licensing support - must be called each time the application starts.
- ReadSettingsRetStr - the DLL entry function that does the initialization of the licensing support but will NOT kill the application when trial expired and unlicensed, instead will return a value greater or equal with 4.
- DisplayRegistrationStr - the DLL entry function that displays (if necessary) the registration dialog - should be called when the user wants to register the application.
So in order to use those functions you must define them and the DLL file name you use.
This code should be added in your C# application.
// This function does all the work
[DllImport("Trial.dll", EntryPoint = "ReadSettingsStr", CharSet = CharSet.Ansi)]
static extern uint InitTrial(String aKeyCode, IntPtr aHWnd);
// Use this function to register the application when the application is running
[DllImport("Trial.dll", EntryPoint = "DisplayRegistrationStr", CharSet = CharSet.Ansi)]
static extern uint DisplayRegistration(String aKeyCode, IntPtr aHWnd);
This code should be added in your VB.NET application.
' This function does all the work
<DllImport("Trial.dll", EntryPoint:="ReadSettingsStr", CharSet:=CharSet.Ansi)> _
Private Shared Function InitTrial(ByVal aKeyCode As String, ByVal aHWnd As IntPtr) As UInteger
End Function
' Use this function to register the application when the application is running
<DllImport("Trial.dll", EntryPoint:="DisplayRegistrationStr", CharSet:=CharSet.Ansi)> _
Private Shared Function DisplayRegistration(ByVal aKeyCode As String, ByVal aHWnd As IntPtr) As UInteger
End Function
Step 2 - Using the licensing support.
Immediately after the main application window is displayed you must initialize licensing support. The InitTrial method must be executed which will actually display the trial messages.
The kLibraryKey string needed to start the trial is defined in the Registration Tab, “Library Key” field, in Advanced Installer.
This code should be added in your C# application.
.........
// 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 = "177291AA00FE97A4A15EDE12F5FEEE6AEF848E711477E84BA999DEAD60CADA84313821C09E4C";
private static void OnInit()
{
try
{
Process process = Process.GetCurrentProcess();
InitTrial(kLibraryKey, process.MainWindowHandle);
}
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());
}
}
........
This code should be added in your VB.NET application.
........
' 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 Shared kLibraryKey As String = "177291AA00FE97A4A15EDE12F5FEEE6AEF848E711477E84BA999DEAD60CADA84313821C09E4C"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim Proc As Process = Process.GetCurrentProcess()
InitTrial(kLibraryKey, Proc.MainWindowHandle)
Catch ex As DllNotFoundException
MessageBox.Show(ex.ToString())
Process.GetCurrentProcess().Kill()
End Try
End Sub
........
Step 3 - Post build event to use the 32-bit licensing library.
If you are using the 32-bit licensing library with Win9x support, you will need to add a post build event to remove the Data Execution Prevention flag from your application.
In Visual Studio you can add a post build event to do that by using the following command line:
call "$(DevEnvDir)..\Tools\vsvars32.bat"
editbin.exe /NXCOMPAT:NO "$(TargetPath)"
When running the application make sure that the trial DLL is
placed in your application folder. Also, options like "Display Frequency Percent", "Show the
trial message at first run" may cause a silent switch to
trial mode.
Sample Projects
Here are some small sample Advanced Installer projects implementing the above
functionality for C# Applications
and VB.NET
Applications.