Hi Richard & Mark,

        First of all, thanx for your help.. sorry for typo mistake and not
providing all the code as I don't wanna confuse you...but here i include all
the necessary declaration...

As for item , Richard wrote :

>4. These statements in hexdump are wrong:
>  hextxt = (Char *)MemHandleLock((MemHandle)hexHandle);
>  StrCopy(hextxt,htxt);
>
>hextxt has been passed in to hexdump as a locked pointer.  So, I think he
>should just do
>  StrCopy(hextxt,htxt);

For resource, we must lock the memory chunk before we can read/write. If you
delete
        hextxt = (Char *)MemHandleLock((MemHandle)hexHandle);
it will give the same error that is Write directly into unallocated chunk of
memory.

>5. Finally, using NULL for any of the params in FrmCustomAlert is bad if
^1,
>^2, and ^3 all exist in the alert, which they must, given they way he calls
>it with different params being null each time.  You have to pass in " " (a
>string with a single blank) for any params you don't want to use.

well, this is not a big issue in this problem as it make no difference even
though i have verify this ...

The error I have is a run time error and is not a compile  error.....

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 ... this error can be solved
with 2 approach :
1. declare the phandle with the size that of the string to be copied from
(source).
2. declare phandle with initial size of 1 then use MemHandleResize in the
same method not in the hexdump .... (this shows that calling MemHandleResize
in the same method as where the handle is declared is different from calling
MemHandleResize in other method ie hexdump ... I couldn't figure out the
reason behind this).

Neither both of his solution is good as the source string is variable in
size.

Error :
======
"test " just read directly from unallocated chunk of memory.

Code :
=====
Char hs[] = "0123456789ABCDEF";
Char *phtxt, *ptxt;
MemHandle phandle;
Int16 plen, clen;

ptxt = "123456789";
clen = plen = StrLen(ptxt);
phandle = MemHandleNew(1); <--if changed to 3*slen instead of 1 ==>OK
phtxt = (Char*) MemHandleLock(phandle);
hexdump(ptxt,phtxt,plen,phandle);
FrmCustomAlert(InfoAlert,"crypto() - 5",ptxt,"NULL");
FrmCustomAlert(InfoAlert,"crypto() - 10","NULL",phtxt); <-- ERROR
MemHandleUnlock(phandle);
MemHandleFree(phandle);

static void hexdump(Char* stxt, Char* hextxt, Int16 slen, MemHandle
hexHandle)
{
MemHandle hhnd;
Char* htxt;
Int16 i;

if (!stxt) stxt="";
hhnd = MemHandleNew(slen ? 3*slen : 1);
htxt = 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 (i) htxt[3*i-1] = '\0'; else htxt[0] = '\0';
MemHandleUnlock(hexHandle);
MemHandleResize(hexHandle,StrLen(htxt)+1);
hextxt = (Char *)MemHandleLock((MemHandle)hexHandle);
StrCopy(hextxt,htxt);
MemHandleUnlock(hhnd);
MemHandleFree(hhnd);
}

Thanks

Regards,
Tan Kuan Eeik
[EMAIL PROTECTED]



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