Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am working on window based app and creating trail software which will expire within 30 days. If user missed to call to activate software all of the Manu Item will disapear and so far I came up with following code failing to give me correct Duration or Span my code is as follow:

C++
COleDateTime timeStart;
COleDateTime timeEnd;
COleDateTime curDateTime;
COleDateTimeSpan Span;
COleDateTimeSpan ActivationSpan(30.0);

int diff;

timeStart = COleDateTime::GetCurrentTime();  // Date and time of the Installation.
timeEnd = timeStart + ActivationSpan;

Span = timeEnd - curDateTime;

diff = Span.GetDays();
CString strMessage;
strMessage.Format("ADDapt was not activated within 30 days of installation and is currently not functional. \n"
     "To activate please call Avtron Field Service at 000-000-0000 ext 1214.\n"
    "The 30 days trial period starts on the day you installed ADDapt.\n"
    "you have %d"" days left to renew ADDapt Software.", (int)Span.GetDays());
AfxMessageBox(strMessage);
Posted
Updated 8-Sep-11 6:04am
v4

This is what I came up with:
C++
COleDateTime timeStart;
COleDateTimeSpan timePassed;
int daysLeft = 0;

timeStart = ???;		// Date and time of the Installation.
timePassed = COleDateTime::GetCurrentTime( ) - timeStart;
daysLeft = 30 - static_cast< int >( timePassed.GetTotalDays( ) );

CString strMessage;
if( daysLeft > 0 )
{
	strMessage.Format( "ADDapt was not activated within 30 days of "
		"installation and is currently not functional.\n"
		"To activate please call Avtron Field Service at 216-642-1230 "
		"ext 1214.\n"
		"The 30 days trial period starts on the day you installed "
		"ADDapt.\n"
		"You have %d days left to renew ADDapt Software.", daysLeft );
}
else
{
	// Format some message indicating the the trial period has elapsed.
	strMessage = "Trial period expired.";
}
AfxMessageBox( strMessage );

I entered the code without a code editor so it might contain typos.

You will need to complete this yourself.
C++
timeStart = ???;

This should be the date and time the application was installed or started for the
first time. When you use the current time the trial period will never decrease and end. The trick is to store it in such a manner that the user cannot easily access and change it and so circumvent you trial period.
[Edit - OP requested explenation]
You need to store the date the application was installed in a file or somewhere in the registry and retrieve when checking the trial period. This cannot be the current time as it should be a date in the past, so if the application was installed a week ago today (01-09-2011) the date you store would be 24-08-2011. In this case the timePassed would be 7 days and daysLeft would be 23 days.

Also I would not put literal string in your code, place them in the resource file. This will make localization in the future a lot easier.
[Edit - OP requested explenation]
You can place string in the string table of the resource file and load them when needed, see this article[^] for details.
 
Share this answer
 
v3
you have mentioned
timeStart = ???; need to be timeStart = COLeDateTime::GetCurrentTime();

After I made package and start looking at message in last line ther days are not changing. ANy idea?

Thank you very much.
 
Share this answer
 
v2
Comments
RaisKazi 1-Sep-11 14:53pm    
You should add your comments just below Solution by using "Have a Question or Comment?"
André Kraak 1-Sep-11 16:05pm    
If you have a question about or comment on the given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution. Thank you.
Change of the day from 30 to 29 is not taking place what is you sugestion on that. Please

When I finish installing software and change the Date to see if startup Message with change the day or not but it did not so it comes from Registry or manually
 
Share this answer
 
v2
Comments
André Kraak 1-Sep-11 16:05pm    
If you have a question about or comment on the given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution. Thank you.
I am fresh out of pond for VC++ and never work on it due to which I didnt understand following statement.:
Also I would not put literal string in your code, place them in the resource file. This will make localization in the future a lot easier.

Could you explain.
 
Share this answer
 
Comments
André Kraak 1-Sep-11 16:05pm    
If you have a question about or comment on the given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution. Thank you.
Vijay Pate 2-Sep-11 7:50am    
What actual meaning of this statement:
Also I would not put literal string in your code, place them in the resource file. This will make localization in the future a lot easier.
Vijay Pate 2-Sep-11 10:53am    
After Trial period expire I need MANU ITEM compltely inactive except Security tab has Log in info and Product activation code.

Any suggestion?

Thank you very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900