> I desperately need a little debugging help.

  well, this one is easy (even if i have had a few beers) :P

> Can anyone tell me why this would bomb (Fatal Exception)? Here's the
> struct and then the code fragment...

  sure.. easy :)

> struct tDocRecord0 {
>     byte  crap;          // because of some flaw in some docs.
>     byte  wVersion;      // 1=plain text, 2=compressed
>     WORD  wSpare;
>     DWORD dwStoryLen;    // in bytes, when decompressed
>     WORD  wNumRecs;      // text records only; =tDocHeader.wNumRecs-1
>     WORD  wRecSize;      // usually 0x1000
>     DWORD dwSpare2;
> };
>
> Boolean SaveEBook(UInt16 cardNo, char *Filename, UInt32 length)
> {
>      VoidHand  RecHandle;
>      Ptr RecPointer;
>      struct tDocRecord0 *theRec;
>      Err theErr;
>      LocalID db;
>
>      theErr = DmCreateDatabase(cardNo, Filename, 'REAd', 'Deep',
>                                false);
>      if (theErr == errNone) {
>
>            if (db) zDB = DmOpenDatabase(cardNo, db, dmModeReadWrite);
>            else {
>                FrmCustomAlert(DebugAlert, "Couldn't find db!",0, 0);
>                return(false);
>            }
>
>            if (zDB == NULL) return(false);
>
>            theRec->wVersion = (byte) 1
>            theRec->dwStoryLen = length;  // <= Bombs here.
>            theRec->wNumRecs = (WORD) 2;
>            theRec->wRecSize = (WORD) 4096;
>            theRec->crap  = (byte) 0;
>            theRec->wSpare  = (WORD)0;
>            theRec->dwSpare2  = (DWORD)0;
>
>            ...
>
> It is bombing right at the "theRec->dwStoryLen = length;" moment.
> I've tried casting it as "theRec->dwStoryLen = (DWORD) length;" as
> well. Both Fatal Exception on me if the length is greater than 1000
> (1024?) or so. (Well, I've seen it succeed at 600, 800 or so, and
> then explode every time at 1400 or so.) I keep thinking there must be
> something else going on, but my debugging attempts so far only narrow
> down to this point! Am I doing something stupid??? (I must be, but
> dang if I can figure it out.)

  where do you allocate the space for theRec? :) maybe time for a:

    theRec = MemPtrNew(...);

  i dont see anywhere above that code where you set the reference
  to a chunk, or even allocate the memory for it :) that might
  be your problem *g* - you'll find it'll complain about writing
  to an unallocated chunk of memory somewhere :p

  see you at palmsource zane :)

// az "my task is done here"
[EMAIL PROTECTED]
http://www.ardiri.com/


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

Reply via email to