> From: Tan Kuan Eeik
>
> I 've mark the link where error occurs and here 's the error and the code.
> This is caused by trying to access the phtxt ...
>

Your code (snipped) has so much extra stuff going on (for example, you pass
in a handle and a pointer to the same block of memory, then unlock and
resize the handle, then lock it again and assign it to the original pointer)
that I just rewrote it entirely.  Here is my code.  (I'm sure someone
reading this would write the code differently, but this closely mirrors your
original code.)

// My version of hexdump, without hexHandle or slen params.
// Creates a hex version of stxt, and returns it in hextxt.
static void hexdump(Char* stxt, Char* hextxt)
{
  MemHandle hhnd;
  Char* htxt;
  Int16 i, slen;
  Char hs[] = "0123456789ABCDEF";

  if (!stxt || StrLen(stxt) == 0)
    StrCopy(hextxt, "");
  else {
    slen = StrLen(stxt);
    hhnd = MemHandleNew(slen ? 3*(slen+1) : 1);
    htxt = (Char *)MemHandleLock(hhnd);
    for(i=0;i<slen;++i) {
      htxt[3*i] = hs[((unsigned char)stxt[i])>>4];
      htxt[3*i+1] = hs[((unsigned char)stxt[i])&15];
      htxt[3*i+2] = ' ';
    }
    if (slen)
      htxt[3*i-1] = '\0';
    else
      htxt[0] = '\0';
    StrCopy(hextxt, htxt);
    MemHandleUnlock(hhnd);
    MemHandleFree(hhnd);
  }
}

// code to call hexdump
static void myTest(void)
{
  Char *phtxt, *ptxt;
  UInt16 plen;
  MemHandle phandle;

  ptxt = "123456789";

  // get space for the hex string
  plen = StrLen(ptxt);
  phandle = MemHandleNew(plen*3+1);
  phtxt = (Char*) MemHandleLock(phandle);

  hexdump(ptxt, phtxt);
  FrmCustomAlert(MyAlertAlert, "crypto() - 5", ptxt, " ");
  FrmCustomAlert(MyAlertAlert,"crypto() - 10", " ", phtxt);
  MemHandleUnlock(phandle);
  MemHandleFree(phandle);
}



-- 
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