library DelphiDLL;
{
element 5 AG / ShareIt!
dll key generator example implementation
version 2.5
}
uses
Windows,
SysUtils,Inifiles;
const // error result codes supported by element 5
ERC_SUCCESS = 0;
ERC_ERROR = 10;
ERC_MEMORY = 11;
ERC_FILE_IO = 12;
ERC_BAD_ARGS = 13;
ERC_BAD_INPUT = 14;
ERC_EXPIRED = 15;
ERC_INTERNAL = 16;
MAX_RESULT = 4000;
// generate a key with some sort of algorithm, in this case, simply
var
co,cp:char;
coa:array[0..1]of char;
glob_username,glob_vdate,glob_title,glob_id:string;
// return the parameters, i.e. key := '';
function GenKeyEx(ap: PInteger; userkey, cckey: PChar): Integer; export; stdcall;
var
RDI:TIniFile;
n,chk,my_expire:integer;
tag, value: PChar; // pointers for input processing
ini_path,regtext,cctext,lang_id,reg_prod,reg_id,reg_name, email,regcode,dereg,exp_date: string; // variables to hold assigned values (add more if needed)
begin
// init error code and check for nil arguments
if (ap = nil) then begin
result := ERC_BAD_INPUT;
exit;
end;
// iterate through args
while (ap^ <> 0) do begin
// get next tag
tag := PChar(ap^); Inc(ap);
if (tag = nil) then break;
// get assigned value for tag
value := PChar(ap^); Inc(ap);
if (value = nil) then break; // oops a tag without a value
// assign tag value
if (StrIComp(tag, 'PRODUCT_ID') = 0) then
begin
reg_prod := StrPas(value);
{Applikationsnamen aus ini lesen}
try
for n:=0 to length(reg_prod)-1 do chk:=strtoint(copy(reg_prod,n,1));
except
reg_prod:='';
end;
if reg_prod<>'' then
begin
try
ini_path:=GetCurrentDir;
if (ini_path<>'') and (copy(ini_path,length(ini_path),1)<>'\') then ini_path:=ini_path+'\';
RDI:=TIniFile.Create(ini_path+reg_prod+'.ini');
if RDI.ValueExists('General','AppName') then reg_prod:=RDI.ReadString('General','AppName','') else reg_prod:='';
if RDI.ValueExists('General','AppTitle') then glob_title:=RDI.ReadString('General','AppTitle','') else glob_title:='';
if glob_title='' then glob_title:=reg_prod;
if RDI.ValueExists('Expire','Days') then my_expire:=RDI.ReadInteger('Expire','Days',0) else my_expire:=0;
finally
RDI.Free;
end;
end;
end
else if (StrIComp(tag, 'ADDITIONAL1') = 0) then
begin
reg_id := StrPas(value);
try
for n:=0 to length(reg_id)-1 do chk:=strtoint(copy(reg_id,n,1));
except
reg_id:='';
end;
end
else if (StrIComp(tag, 'LANGUAGE_ID') = 0) then
begin
lang_id := StrPas(value);
end
else if (StrIComp(tag, 'REG_NAME') = 0) then
begin
reg_name := StrPas(value);
end
else if (StrIComp(tag, 'EMAIL') = 0) then
begin
email := StrPas(value);
end;
// add more lines if needed ...
end;
//Zu lanen Regnamen verhindern
reg_name:=trim(reg_name);
if length(reg_name)>24 then reg_name:=copy(reg_name,1,24);
// generate key - change to your liking
if (reg_prod<>'') and (reg_name <> '') and (reg_id <>'') and (length(reg_id)=10) and (email <> '') then begin
reg_name:=glob_username;
regcode:='dummykey';
if lang_id='2' then
begin
regtext:='Vielen Dank für Ihre Registrierung!'#13#10#13#10'Produkt: '+glob_title+#13#10#13#10+
'Name: '+reg_name+#13#10'ID: '+reg_id+#13#10'Code: '+regcode+#13#10#13#10;
end
else
begin
regtext:='Thank you for registering!'#13#10#13#10'Product: '+glob_title+#13#10#13#10+
'Name: '+reg_name+#13#10'ID: '+reg_id+#13#10'Code: '+regcode+#13#10#13#10;
end;
cctext:='Produkt: '+reg_prod+#13#10#13#10+
'Name: '+reg_name+#13#10'ID: '+reg_id+
#13#10'Code: '+regcode;
StrLCopy(cckey, PCHar(cctext), MAX_RESULT);
StrLCopy(userkey, PChar(regtext), MAX_RESULT);
result := ERC_SUCCESS;
end else begin
result := ERC_BAD_INPUT;
end;
end;
exports
GenKeyEx index 1 name 'GenKeyEx'; // do not change
// library initialization code
begin
// if required add your init code here
end.