HBufC question...

Login to reply to this topic.
Fri, 2005-12-09 11:03
Joined: 2003-11-28
Forum posts: 35
hello,

I have a callback function that is called at certain time intervals. in this function I receive a string buffer from a nwtwork. I want to save this string buffer in a bigger buffer that. Initially I don't know the size of the buffer, so how to alocate and realocate the size of the buffer ? I want to use HBufC, because the size of the string buffer is unknown.

My function is:

.........................

HBufC* iBuffer;

.........................

CLoginDlg::CLoginDlg()
{
// how to initialize the buffer first, becuse I don't know the size of the data
iBuffer = HBufC::NewL();
}

CLoginDlg::~CLoginDlg()
{
delete iBuffer;
iBuffer = NULL;
}

void CLoginDlg::ClientBodyReceived(const TDesC8& aBodyData)
{
// here I need to add aBodyData which is TDesC8 to iBuffer which is HBufC16 pointer
}

Thanks.

Fri, 2005-12-09 11:47
Joined: 2005-08-11
Forum posts: 278
Re: HBufC question...
hi you can do like this:

HBufC *hello= HBufC::NewL(aBodyData.Length());
TPtr ptr(hello->Des());
for(int i=0;i<aBodyData.Length();i++)
{
   ptr.Append(aBodyData[i]);
}


now youe HBufC will contain the aBodyData
hope this one helps you out...
Fri, 2005-12-09 12:00
Joined: 2005-08-11
Forum posts: 278
Re: HBufC question...
Oh i forgot to answer someother thing..
you can initialise you HBufc  wit 0,1 ,2 or anything...
and after wards you can reallocate as :

iBuffer= iBuffer->ReAllocL(5);//new length
ptr.Set(iBuffer);//it must be set again.since the new buf may be in a different memory location.
  • Login to reply to this topic.