You can use something like the following to do stuff after your app exits.
The code copies a function to feature memory, registers it to receive
a system notification, and sends a deferred notification that includes
a struct full of whatever info the function needs to do it's thing.
Sometime in the very near future, the function will be called with the
notification, will use the info you passed it to do stuff (delete your
app in your case), and then removes itself (deletes the feature).
The same thing can be done with a proc alarm.
-----------------------------------------------------------------------------------------------------------------------------------
// The following code uses a system notification.
// Call the install routine just before returning from PilotMain.
// The notification will be broadcast the next time EvtGetEvent() is called,
// which should be when the next app begins/resumes. The info struct will be
// managed by the OS;
//
// The notification can be replaced by a proc alarm. Two advantages of the alarm
// are that 1) you can delay the delete code execution by the duration
of the alarm,
// and 2) the alarm will wake the processor, if it is asleep. The info
struct will
// have to be allocated in heap or a feature, and passed as the alarm parameter.
// Don't forget to free the info struct in the delete proc.
#define kAppCreatorID 'xxxx' // your app creator id
#define kDeleteSelfFeatureNum 0 // change, if it
interferes with any
of your own
typedef struct
{
LocalID appDbID; // used to
delete app database
// add other info here - whatever else is required to delete
everything to do with the app
} DeleteSelfInfoType;
static Err PrvDeleteSelfProc(SysNotifyParamType* param)
{
DeleteSelfInfoType *info = (DeleteSelfInfoType*)param->notifyDetailsP;
SysNotifyUnregister(0,(LocalID)PrvDeleteSelfProc,kAppCreatorID,sysNotifyNormalPriority);
DmDeleteDatabase(0,info->appDbID);
// whatever else is required to delete everything to do with the app
// use the info passed in the info structure
FtrUnregister(kAppCreatorID,kDeleteSelfFeatureNum);
return errNone;
}
static Err PrvDeleteSelfInstall(void)
{
SysNotifyParamType notify;
PrvDeleteSelfType info;
void *feature;
UInt32 size;
Err err;
// place copy of delete code in feature
size = (UInt32)PrvDeleteSelfInstall - (UInt32)PrvDeleteSelfProc;
err = FtrPtrNew(kAppCreatorID,kDeleteSelfFeatureNum,size,&feature);
if (err != errNone)
return err;
DmWrite(feature,0,PrvDeleteSelfProc,size);
// register the code to receive a notification
err =
SysNotifyRegister(0,(LocalID)feature,kAppCreatorID,(SysNotifyProcPtr)feature,sysNotifyNormalPriority,0);
if (err != errNone)
return err;
// send a deferred notification that will be broadcast the next time
EvtGetEvent() is called
notify.notifyType = type;
notify.broadcaster = kAppCreatorID;
notify.notifyDetailsP = &info;
info.appDbID = ??; // retrieve the app DbID however you like
// fill in the other info you'll need
return SysNotifyBroadcastDeferred(¬ify,sizeof(info));
}
-----------------------------------------------------------------------------------------------------------------------------------
On Dec 6, 2007 10:40 PM, Hynek Sladky <[EMAIL PROTECTED]> wrote:
> If I made app for launching apps from SD/MMC card i set this bit and
> when app ended it deleted itself (without reset). But all preferences
> and other databases related to this app remain in memory!
>
> Hynek Sladky
>
>
>
> Roger Stringer wrote:
> > At 03:15 AM 12/6/2007, you wrote:
> >
> >> Subject: Self-deleting app
> >> From: "Baxter" <[EMAIL PROTECTED]>
> >> Date: Wed, 5 Dec 2007 19:17:02 -0800
> >> X-Message-Number: 6
> >>
> >> Anyone have an idea on how to do this?
> >
> >
> > Set the recycle bit (don't forget ALL related files) and then do a soft
> > reset.
> >
> > --
> > For information on using the ACCESS Developer Forums, or to unsubscribe,
> > please see http://www.access-company.com/developers/forums/
> >
> >
> > Roger Stringer
> > Marietta Systems, Inc. (www.rf-tp.com <http://www.rf-tp.com/>)
>
>
> --
> For information on using the ACCESS Developer Forums, or to unsubscribe,
> please see http://www.access-company.com/developers/forums/
>
--
[Jeff Loucks, Gig Harbor, WA, USA]
--
For information on using the ACCESS Developer Forums, or to unsubscribe, please
see http://www.access-company.com/developers/forums/