Subject: Database write causes a reset.
From: Peter Hamilton-Scott <[EMAIL PROTECTED]>
Date: Thu, 03 Jun 2004 20:06:30 +0100

Guys, below is a procedure I call in my app. It works fine until it gets
to the DmWrite at which point it cause a reset. I've basically copied
the code from elsewhere and tweaked it. My DBRef variable is fine. All
I'm trying to do is to create the appinfo control record. I don't do
anything with the structure yet but I'd like to think that once I've got
the handle and converted it to a local id, then whether I initialise the
structure or not is neither here nor there. Could someone take a look at
this and tell me what I'm doing wrong, or perhaps what I'm not doing?

Thanks.

void PopulateDatabase(void) {
     typedef struct   {
         AppInfoType AppInfo;
         UInt16 Test;
     } TestDBControl;

     TestDBControl *ControlRecord = NULL;
     MemHandle Handle;
     LocalID LocalId;
     LocalID DBId;
     UInt16 CardNo;

     if(DmOpenDatabaseInfo(_DBRef, &DBId, NULL, NULL, &CardNo, NULL) ==
errNone)      {
         Handle = DmNewHandle(_DBRef, sizeof(TestDBControl));
         if(Handle)          {
             LocalId = MemHandleToLocalID(Handle);
             if(DmSetDatabaseInfo(CardNo, DBId, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, &LocalId, NULL, NULL, NULL)
                        == errNone)      {
                 ControlRecord = (TestDBControl *) MemHandleLock(Handle);
                 if(ControlRecord != NULL)        {
                     DmWrite(Handle, (UInt32) 0, ControlRecord, (UInt32)
                        sizeof(TestDBControl));
                     MemPtrUnlock(ControlRecord);
                 }
             }
             MemHandleFree(Handle);
         }
     }
     return;
}


Two obvious errors
1) Your DmWrite (Handle, ...) should have ControlRecord as the first parameter
        This is probably causing the reset

2) Why are you freeing the Handle after assigning it to ApplInfo?
        That's a reset waiting to happen at a later time !!!
     You should only free the handle if the DmSetDatabaseInfo fails!

Also, I'd return a Boolean value from this function indicating whether it succeeded or failed, but that's just my programming style...


Roger Stringer Marietta Systems, Inc. (www.mariettasystems.com)


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

Reply via email to