Page 1 of 1

UserData and Expiration Date

Posted: Wed Oct 23, 2019 6:53 am
by MrLot
I have si.pUserData set to what I want but it doesn't show up in license once it has been generated.

I can't seem to get the user data to be added. What am I missing?

How would I get a string to be added to user data?


Also how would I have a DateTimePicker1.Date to be set as expiration date in keygen?

How would I set statement:
si.dwExpDate := Cardinal(DateTimePicker1.Date);

^^ this doesn't work... looking for solution.


I am using Delphi to program.

Re: UserData and Expiration Date

Posted: Wed Oct 23, 2019 8:01 am
by Admin
How would I get a string to be added to user data?
It seems your forgot to specify "HAS_USER_DATA" in si.flags:

Code: Select all

si.flags := ... or HAS_USER_DATA;
How would I set statement:
si.dwExpDate := Cardinal(DateTimePicker1.Date);
You have to use the following code for it:

Code: Select all

#define MAKEDATE(y, m, d) (DWORD)((y << 16) + (m <<8) + d)
Where "y" = "year", "m" = "month", "d" = "day" and "<<" = "shl". Also don't forget to specify "HAS_EXP_DATE" in si.flags.

Re: UserData and Expiration Date

Posted: Wed Oct 23, 2019 9:10 am
by MrLot
How do I get a datetimepicker to get correct value? MAKEDATE is not a function or string anywhere. Even if I made it, that only allows for static input not dynamic from a datetimepicker in delphi.

I have a DateTimePicker that I want to pull the date from and set as expiration date.

Re: UserData and Expiration Date

Posted: Wed Oct 23, 2019 11:43 am
by Admin

Code: Select all

var
  y, m, d : Word;
begin
  DecodeDate(DateTimePicker1.Date, y, m, d);
  si.dwExpDate := (y shl 16) + (m shl 8) + d;

Re: UserData and Expiration Date

Posted: Sun Dec 01, 2019 11:51 pm
by MrLot
Thank you, this is working now. However, is the UserData supposed to be in a specific format or char type? I've specified it, but it's not being added to the license. I have the flag specified, so that's not the problem.

Re: UserData and Expiration Date

Posted: Mon Dec 02, 2019 8:38 am
by Admin
"UserData" is just a byte array. You can store any data in this field.

Re: UserData and Expiration Date

Posted: Mon Dec 02, 2019 4:42 pm
by MrLot
No matter what I do, it's not in the right format and is giving me errors.

Incompatible types: 'PByte' and 'System.TArray<SystemBytes>'
or

Incompatible types: 'PByte' and 'System.String'


I am using:
si.PUserData := TEncoding.UTF8.GetBytes(mystring);

Re: UserData and Expiration Date

Posted: Tue Dec 03, 2019 12:21 pm
by Admin

Code: Select all

var user_data: array [0..20] of Byte;
...
user_data[0] := 1;
user_data[2] := 2;
..
user_data[19] := 20;
si.pUserData := @user_data[0];
si.nUserDataLength:= SizeOf(user_data);

Re: UserData and Expiration Date

Posted: Wed Jan 22, 2020 1:16 am
by MrLot
Thank you, this works great.

However, what if you have a string in which you want to place into user data?

Re: UserData and Expiration Date

Posted: Wed Jan 22, 2020 6:06 am
by Admin
I recommend to store such string in UTF8/Base64 and decode it in a protected program.