HBufC question...
| Fri, 2005-12-09 11:03 | |
|
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. |
|






Forum posts: 278
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...
Forum posts: 278
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.