> VoidHand sh;
> CharPtr s;
>
> sh = MemHandleNew(SIZE);
> fetch(s,sh);
> // Now s is garbage and anything that uses it crashes
>
> }
>
> void fetch(CharPtr s, VoidHand sh)
> {
> s = MemHandleLock(sh);
> StrCopy(s,"custard");
> MemHandleUnlock(sh);
The problem is that s itself is never getting set in the main segment,
because the value you pass in to fetch is not returned.
solution 1: pass a pointer to s:
VoidHand sh;
CharPtr s;
sh = MemHandleNew(SIZE);
fetch(&s,sh);
void fetch(CharPtr *s, VoidHand sh)
{
*s = MemHandleLock(sh);
StrCopy(*s,"custard");
MemHandleUnlock(sh);
}
solution 2: lock sh before calling fetch:
VoidHand sh;
CharPtr s;
sh = MemHandleNew(SIZE);
s = MemHandleLock(sh);
fetch(s,sh);
void fetch(CharPtr s, VoidHand sh)
{
StrCopy(s,"custard");
MemHandleUnlock(sh);
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/