This is what I came up with:
COleDateTime timeStart;
COleDateTimeSpan timePassed;
int daysLeft = 0;
timeStart = ???; 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
{
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.
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.