Hello folks,

I'm trying to intercept the insertion of a memory card and to scan its 
contents. Here is what I'm doing:

1) On sysAppLaunchCmdSystemReset and sysAppLaunchCmdSyncNotify I register to 
receive notifications about the sysNotifyVolumeMountedEvent event:

UInt32 PilotMain (UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
    UInt16 cardNo;
    LocalID dbID;
    UInt32 romVersion;

    switch (cmd)
    {
        case sysAppLaunchCmdNormalLaunch:
            AppStart ();
            FrmGotoForm (kMainForm);
            AppEventLoop ();
            AppStop ();
            break;
        case sysAppLaunchCmdSystemReset:
        case sysAppLaunchCmdSyncNotify:
            FtrGet (sysFtrCreator, sysFtrNumROMVersion, &romVersion);
            if (romVersion >= version40)
                SysNotifyRegister (cardNo, dbID, sysNotifyVolumeMountedEvent, 
NULL, sysNotifyNormalPriority, NULL);
            break;
        case sysAppLaunchCmdNotify:
            HandleNotification ((SysNotifyParamType *) cmdPBP);
            break;
        default:
            break;
    }
    return 0;
}

2) When the notification arrives, I basically do

void HandleNotification (SysNotifyParamType *np)
{
    switch (np->notifyType)
    {
        case sysNotifyVolumeMountedEvent:
            AppStart ();
            FrmGotoForm (kScanningMemoryCardForm);
            AppEventLoop ();
            AppStop ();
            break;
        default:
            break;
    }
}

The code is written so that it doesn't use any global or static variables. This 
works fine on the Tungsten E simulator, using HostFS to simulate a card with a 
directory on the PC. True, I can't "insert a card" in the simulator - but the 
sysNotifyVolumeMountedEvent event is broadcast on soft reset too (makes sense - 
the volume has to be mounted during reset), and when I reset the simulator, my 
application is launched and it scans the card.

However, when I try it on a real device (Tungsten E), as soon as I insert a 
card (or during reset, if a card is left in the slot) I get a system crash with 
the memory manager complaining about a NULL pointer. I've been using a 
FrmCustomAlert to display debugging messages and, interestingly, the custom 
alert is flashed on the screen - but there is no waiting for the user to tap on 
its button; instead I immediately get the message for the crash.

Another thing. The crash does not happen and the application scans the inserted 
card properly, if the application was running at the moment when the card was 
inserted.

Any hints what might be the problem? The documentation explicitly says that you 
*can* use the user interface during notifications. Yet the program crashes as 
if there is no current form or something. And why doesn't it crash under the 
simulator? Is there anything obviuous that I might be missing?

Regards,
Vesselin
-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to