using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Text;
namespace RomanNumerals
{
public class LicenseHelper
{
const string PWD = "---Replace with your Developer Key---";
[DllImport("pgslicmt.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern pgslic_status
checkLicense(
byte[] path,
byte[] pwd,
byte[] key,
byte[] appName,
byte[] appInfo,
byte[] cxnOpts);
[DllImport("pgslicmt.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("pgslicmt.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("pgslicmt.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("pgslicmt.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("pgslicmt.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern System.IntPtr
getSetting(
byte[] settingName);
[DllImport("pgslicmt.dll", CallingConvention = CallingConvention.Cdecl)]
public bool CheckLicense(string licDir, string key, string appName)
{
switch (
checkLicense(Encoding.ASCII.GetBytes(licDir), Encoding.ASCII.GetBytes(PWD), Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(appName), Encoding.ASCII.GetBytes(
""), Encoding.ASCII.GetBytes(
"")))
{
case pgslic_status.LICENSE_OK:
break;
case pgslic_status.LICENSE_ERROR:
System.Windows.Forms.MessageBox.Show(
"License not valid: " + Marshal.PtrToStringAnsi(
getLastError()),
"License", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return false;
case pgslic_status.LICENSE_EXPIRED:
System.Windows.Forms.MessageBox.Show("License expired.\nClick on OK to activate or Cancel to exit.", "License", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand);
return false;
default:
throw new Exception("Unexpected license status value");
}
return true;
}
public void ShowLicenseInfo()
{
string licenseInfo = Marshal.PtrToStringAnsi(
getAppName()) +
" 1.0\n";
licenseInfo +=
"Licensed to " + Marshal.PtrToStringAnsi(
getClientName()) +
"\n";
{
licenseInfo += "License never expires\n";
}
else
{
licenseInfo +=
"License expires on " + Marshal.PtrToStringAnsi(
getExpiryDate()) +
"\n";
}
licenseInfo +=
"Maximum number = " + Marshal.PtrToStringAnsi(
getSetting(Encoding.ASCII.GetBytes(
"MaxLimit")));
System.Windows.Forms.MessageBox.Show(licenseInfo, "License Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public int GetMaxLimit()
{
return Convert.ToInt32(Marshal.PtrToStringAnsi(
getSetting(Encoding.ASCII.GetBytes(
"MaxLimit"))));
}
}
}
PGSLIC_API const char * getSetting(const char *settingName)
PGSLIC_API int isPerpetual()
PGSLIC_API const char * getExpiryDate()
PGSLIC_API const char * getAppName()
@ LICENSE_STALE
Definition: pgslic.h:96
@ LICENSE_WARNING
Definition: pgslic.h:96
@ LICENSE_EXPIRED
Definition: pgslic.h:96
@ LICENSE_OK
Definition: pgslic.h:96
@ LICENSE_ERROR
Definition: pgslic.h:96
PGSLIC_API const char * getClientName()
PGSLIC_API const char * getLastError()
PGSLIC_API LicenseStatus checkLicense(const char *licPath, const char *pwd, const char *key, const char *appName, const char *appInfo="", const char *cxnOpts="")