Set the application preferences with an integer that keeps incrementing
until it's expired or a DateType that will have the expiration date, or
both.
Call 'demoExpired' from your application's startup function. It will return
true if the demo has expired (in this case, if the application has been used
for more than ten days *or* run more than twenty times).
<<<CODE>>>
typedef struct {
UInt8 numLaunches;
DateType expirationDate;
} AppPrefType;
...
#define APP_CREATOR_ID ('abcd') // Application creator registered ID
#define APP_PREF_ID (0x00) // You can have multiple
preference structures for a single application
#define APP_VERSION (0x01) // What version your app is
#define NUM_DAYS_TILL_EXP (10) // Number of days till the program
expires
#define NUM_LAUNCHES (20) // Number of times you can play the game
until it stops working
...
AppPrefType gAppPrefs; // Global variable with the preferences
...
Boolean demoExpired(void) { // Returns true if the demo has expired
Boolean expired = false;
UInt16 sizeofAppPrefs;
DateType currentDate; // Temp holder while we convert current time in
seconds to number of days
UInt32 currentSeconds = TimGetSeconds(); // Get the current time so
we can run checks
// Read the saved preferences / saved-state information.
sizeofAppPrefs= sizeof(AppPrefType);
if (PrefGetAppPreferences(APP_CREATOR, APP_PREF_ID, &gAppPrefs,
&sizeofAppPrefs, true) == noPreferenceFound) {
// No preferences where found for this app so set the defaults
gAppPrefs.numLaunches = 1;
DateSecondsToDate(currentSeconds + (NUM_DAYS_TILL_EXP * 60 * 60 * 24),
&gAppPrefs.expirationDate); // Set the date it will expire
expired = false; // It's still good since this is the first time the
prog's been run
}
// Increment the number of launches
//gAppPrefs.numLaunches++; // Don't need it here, done when checking the
value
// Setup the checks for demo status
DateSecondsToDate(currentSeconds, ¤tDate);
// Check the status of the demo
if (DateToDays(currentDate) < DateToDays(gAppPrefs.expirationDate) || // Is
it after the expiration date?
gAppPrefs.numLaunches++ > NUM_LAUNCHES) // Has the program been run more
than ten times?
expired = true;
// Set the preferences for the next time the program's run
PrefSetAppPreferences (APP_CREATOR, APP_PREF_ID, APP_VERSION, &gAppPrefs,
sizeof (AppPrefType), true);
// Return what we decided on
return expired;
} // demoExpired
<<<END>>>
I didn't test this but it should give you the basic idea. Let me know if it
works.
Note that an application's preferencs are discarded when the application is
deleted from the handheld. The user can bypass this demo by just deleting
and reinstalling the application on the Palm. Play around with it on POSE
to see what happens.
Since you've created a program now, I'm sure you know how to work with
databases. One way to bypass the preferences deletion
Jimi
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/