> From: Tan Kuan Eeik
>
> the thing is I don't understand that :
>
> 1. when we initialize the phandle in myTest() ,
> phtxt(hextxt)="" is pointing to 0x25ec.
> 2. when we resize phandle in hexdump(),
> hextxt(phtxt)="12 34" is pointing to 0x2e00.

When you unlock a handle and resize it, the memory block is likely to move
(especially if you make it bigger!).  That's the whole purpose of Handles --
to provide a means to allocate and use moveable memory blocks.  When you
lock a handle, you get a pointer to the memory and then you can access it.
When it is unlocked, the Memory Manager can move it around to make room for
memory allocation.

> hexdump(Char* stxt, Char* hextxt, MemHandle phandle)
> {
>       ...........
>       MemHandleUnlock(phandle);
>       MemHandleResize(phandle, 3*StrLen(slen+1));
>       hextxt = (Char*) MemHandleLock(phandle); -->phtxt is
> allocated at 0x2e00
>       StrCopy(hextxt, htxt);
>       ........
> }

I don't understand why you are passing in both the pointer (hextxt) and the
handle (phandle).  Just use one.  If you pass in the pointer, the memory it
points to is locked and you can use StrCopy() to copy your string.  This
requires you to pass in a pointer to a string that is big enough to hold the
text you want to copy.  If you pass in the handle, it should be unlocked
when you pass it in, then you can resize it, lock it to get a pointer, copy
text to the string, and finally unlock it.


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