20 October 2005

How to assign writable descriptor in Symbian

When you need a writable descriptor like TDes8 to pass as reference into a function ( like FillMyDes(TDes8& aDes) ), and later this function will fill it with data, you probably want to allocate this descriptor in Symbian heap. So you are writing this code:

    HBufC8* iHeapDes = HBufC8::NewL(KSIZE);

And then you want to store writable descriptor for later use like this:

    TPtr8 iWriteDes(NULL,0);
    iWriteDes = iHeapDes->Des();

But iWriteDes don’t becomes what you really wanted. Because you make mistake in previous line of code, you haven’t assigned descriptor, you just trieŠ² to copy the data contained in heap descriptor to you writable descriptor. The right code will look like this:

    iWriteDes.Set( iHeapDes->Des() );

Now you got correct writable descriptor in iWriteDes.

No comments: