Iīd do it like this

 void AAA(void)
 {
    MemHandle iBuffH;
    UInt8* iBuffPtr=NULL; 
    UInt16 iLen;

    iBuffH = MemHandleNew(1);
    iLen = BBB(iBuffH);
 
    iBuffPtr = MemHandleLock(iBuffH);
    //do something with iBuffPtr
        
    MemHandleUnlock(iBuffH);
    MemHandleFree(iBuffH);
 }
 
 UInt16 BBB(MemHandle iDataH)
 {
    UInt16 iLen;
    Char sStr[] = "Test Data";
    Err err;
        
    iLen = StrLen(sStr);
    MemHandleResize(iDataH ,iLen), /*I donīt remember
the order of the parameters*/
    iDataPtr = MemHandleLock(iDataH);
    err = MemMove (iDataPtr, sStr,iLen+1);
    MemHandleUnlock(iDataH);

    return iLen+1;
 }

The problem with your code is that when you create the
new pointer in BBB, it changes (not necesarily, but
offten) the pointer location. So in AAA the pointer is
pointing somewhere else in the memory. 

It might not be the most elegant solution,but it works
fine.

Sebas.
--- Ken <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> Below is sample code of what I would like to do
> (which does not work).
> 
> Function BBB allocates memory and loads the buffer
> and then
> AAA uses the data and then deletes the buffer.
> 
> The pointer to the memory buffer does not get passed
> back to AAA
> correctly.
> 
> So I have missed something in the way the MemPtr
> function work.
> 
> I would like to know how to make it work with the
> MemPtr functions.
> 
> Thanks,
> Ken
> 
>
//----------------------------------------------------------------------
>
//----------------------------------------------------------------------
> void AAA(void)
> {
>    UInt8* iBuffPtr=NULL; 
>    UInt16 iLen;
>       
>    iLen = BBB(iBuffPtr);
>       
>    //do something with iBuffPtr
>       
>    MemPtrFree(iBuffPtr);
> }
> 
>
//----------------------------------------------------------------------
>
//----------------------------------------------------------------------
> UInt16 BBB(UInt8* iDataPtr)
> {
>    UInt16 iLen;
>    Char sStr[] = "Test Data";
>    Err err;
>       
>    iLen = StrLen(sStr);
>    iDataPtr = (UInt8*)MemPtrNew(iLen+1);
>    err = MemMove (iDataPtr, sStr,iLen+1);
>    return iLen+1;
> }
> 
>
//----------------------------------------------------------------------
>
//----------------------------------------------------------------------
> 
> -- 
> For information on using the Palm Developer Forums,
> or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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

Reply via email to