unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, CustomWinlicenseSDK;


type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    NameEdit: TEdit;
    OrgEdit: TEdit;
    HardIdEdit: TEdit;
    CustomEdit: TEdit;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    NumDaysEdit: TEdit;
    NumExecEdit: TEdit;
    ExpDate: TDateTimePicker;
    EnableDateCheck: TCheckBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    Label4: TLabel;
    FileNameEdit: TEdit;
    GenFileKey: TButton;
    GroupBox5: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    RegistryEdit: TEdit;
    Button2: TButton;
    Edit3: TEdit;
    RegValueEdit: TEdit;
    LicRegEdit: TEdit;
    RadioGroup1: TRadioGroup;
    Button3: TButton;
    GroupBox6: TGroupBox;
    GenStaticSmartKey: TButton;
    SmartEdit: TEdit;
    TextKeyMemo: TMemo;
    GenDynamicSmartKey: TButton;
    procedure GenFileKeyClick(Sender: TObject);
    procedure EnableDateCheckClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure GenStaticSmartKeyClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure GenDynamicSmartKeyClick(Sender: TObject);
  private
     { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.GenFileKeyClick(Sender: TObject);
var
  LicenseKeyBuff: ARRAY[0..4000] of AnsiChar;
  SizeKey, i: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  ExpDateSysTime: SYSTEMTIME;
  NumDays, NumExec: integer;
  KeyFile: FILE OF AnsiChar;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
    DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);

  SizeKey := WLCustomGenLicenseFileKey(pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, 0, 0, 0, LicenseKeyBuff) ;

 // save generated key in user file

 AssignFile(KeyFile, FileNameEdit.Text);

 Rewrite(KeyFile);

 for i:= 0 TO SizeKey-1 DO
   Write(KeyFile, LicenseKeyBuff[i]);

 CloseFile(KeyFile);

  MessageBox(0, 'A License key file has been generated', 'License Key Generator SDK', MB_OK);

end;

procedure TForm1.EnableDateCheckClick(Sender: TObject);
begin

 if EnableDateCheck.State =  cbChecked  then
    ExpDate.Enabled := True
 else
    ExpDate.Enabled := False;


end;

procedure TForm1.Button3Click(Sender: TObject);
var
  ExpDateSysTime: SYSTEMTIME;
  LicenseKeyBuff: ARRAY[0..4000] of AnsiChar;
  SizeKey: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  NumDays, NumExec: integer;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
   DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);

  SizeKey := WLCustomGenLicenseTextKey(pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, 0, 0, 0, LicenseKeyBuff) ;
  TextKeyMemo.Text := LicenseKeyBuff;

end;

procedure TForm1.GenStaticSmartKeyClick(Sender: TObject);
var
  ExpDateSysTime: SYSTEMTIME;
  LicenseKeyBuff: ARRAY[0..1000] of AnsiChar;
  SizeKey: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  NumDays, NumExec: integer;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
   DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);
                     
  SizeKey := WLCustomGenLicenseSmartKey(pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, LicenseKeyBuff) ;
  SmartEdit.Text := LicenseKeyBuff;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ExpDateSysTime: SYSTEMTIME;
  LicenseKeyBuff: ARRAY[0..4000] of AnsiChar;
  SizeKey, i: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  NumDays, NumExec: integer;
  KeyFile: FILE OF AnsiChar;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
   DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);

  SizeKey := WLCustomGenLicenseRegistryKey(pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, 0, 0, 0, PAnsiChar('HKEY_LOCAL_MACHINE\' + RegistryEdit.Text), PAnsiChar(RegValueEdit.Text), LicenseKeyBuff) ;

 // save generated key in user file

 AssignFile(KeyFile, LicRegEdit.Text);

 Rewrite(KeyFile);

 for i:= 0 TO SizeKey-1 DO
   Write(KeyFile, LicenseKeyBuff[i]);

 CloseFile(KeyFile);

  MessageBox(0, 'A License key file has been generated', 'License Key Generator SDK', MB_OK);

end;

procedure TForm1.GenDynamicSmartKeyClick(Sender: TObject);
var                  
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  LicenseKeyBuff: ARRAY[0..1000] of AnsiChar;
  LicenseFeatures: sLicenseFeatures;
  SizeKey: Integer;
  NumDays, NumExec: integer;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  // initialize LicenseFeatures

  FillChar(LicenseFeatures, SizeOf(sLicenseFeatures), 0);
  LicenseFeatures.cb := SizeOf(sLicenseFeatures);

  // set LicenseFeatures according to GUI settings

  LicenseFeatures.NumDays := NumDays;
  LicenseFeatures.NumExec := NumExec;

  if EnableDateCheck.Checked then
    DateTimeToSystemTime(ExpDate.Date, LicenseFeatures.InstallDate);

  // Generate Dynamic SmartKey and display it on GUI

  SizeKey := WLCustomGenLicenseDynSmartKey(pName, pOrg, pCustom, pHardId, LicenseFeatures, LicenseKeyBuff);
  SmartEdit.Text := LicenseKeyBuff;

end;

end.
