RBuf8 to char* in Symbian C++

I am downloading a text string from a web service into an RBuf8 using this kind of code (it works..)

void CMyApp::BodyReceivedL( const TDesC8& data ) {
    int newLength = iTextBuffer.Length() + data.Length();
    if (iTextBuffer.MaxLength() < newLength)
        {
            iTextBuffer.ReAllocL(newLength);
        }
    iTextBuffer.Append(data);
}

I want to then convert the RBuf8 into a char* string I can display in a label or whatever.. or for the purposes of debug, display in

RDebug::Printf("downloading text %S", charstring);

edit for clarity..

My conversion function looks like this..

void CMyApp::DownloadCompleteL() { { RBuf16 buf; buf.CreateL(iTextBuffer.Length()); buf.Copy(iTextBuffer);

    RDebug::Printf("downloaded text %S", buf);
    iTextBuffer.SetLength(0);
    iTextBuffer.ReAlloc(0);                                 
}

But this still causes a crash. I am using S60 3rd Edition FP2 v1.1

Answers


What you may need is something to the effect of:

RDebug::Print( _L( "downloaded text %S" ), &buf );

This tutorial may help you.


void RBuf16::Copy(const TDesC8&) will take an 8bit descriptor and convert it into a 16bit descriptor.

You should be able to display any 16bit descriptor on the screen. If it doesn't seem to work, post the specific API you're using.

When an API can be used with an undefined number of parameters (like void RDebug::Printf(const char*, ...) ), %S is used for "pointer to 16bit descriptor". Note the uppercase %S.


Thanks, the %S is a helpful reminder.

However, this doesn't seem to work.. my conversion function looks like this..

void CMyApp::DownloadCompleteL() {
    {
        RBuf16 buf;
        buf.CreateL(iTextBuffer.Length());
        buf.Copy(iTextBuffer);

        RDebug::Printf("downloaded text %S", buf);
        iTextBuffer.SetLength(0);
        iTextBuffer.ReAlloc(0);                 
    }

But this still causes a crash. I am using S60 3rd Edition FP2 v1.1


You have to supply a pointer to the descriptor in RDebuf::Printf so it should be

RDebug::Print(_L("downloaded text %S"), &buf);

Although use of _L is discouraged. _LIT macro is preferred.


As stated by quickrecipesonsymbainosblogspotcom, you need to pass a pointer to the descriptor.

RDebug::Printf("downloaded text %S", &buf); //note the address-of operator

This works because RBuf8 is derived from TDes8 (and the same with the 16-bit versions).


Need Your Help

for loop with array pointers, setting values to the pointer

c arrays pointers

I'm completely new to C and have to work with pointers which are kind of confusing right now.

UIScrollView only required when keyboard is displayed

iphone ios uiview uiscrollview

I have tried multiple implementations of a scroll view to handle a keyboard's presence, including apple's own. I can't get any of them to work.