Problem regarding HBufC

Login to reply to this topic.
Mon, 2006-04-24 07:20
Joined: 2006-04-08
Forum posts: 41
hi,
i want to receive data from socket by the following code.........

HBufC* ReadBuffer;

TPtr8 p=ReadBuffer->Des();
//Function is leaving at above statement.

iSocket.RecvFrom(p,anAddr,0,iStatus);

Can anyone suggest how to accomplish the above task.

Mon, 2006-04-24 07:28
Joined: 2005-11-20
Forum posts: 1246
Re: Problem regarding HBufC
Merely declaring the HBufC is not enough. You have to allocate memory for it with NewL or NewLC.

René Brunner

Mon, 2006-04-24 07:29
Joined: 2005-08-11
Forum posts: 278
Re: Problem regarding HBufC
Hi Amit ,

you should allocate memory for your HBufC before you use it. like for example

HBufC* heapBuf = HBufC::NewL(10);

Please go through this link:
http://descriptors.blogspot.com/
for more information.

max_i
Mon, 2006-04-24 08:10
Joined: 2006-04-08
Forum posts: 41
Re: Problem regarding HBufC
Sorry buddies,
I have already done NewL for HBufC. I give u the modified code:

HBufC* ReadBuffer=HBufC::NewL(500);

TPtr8 p=ReadBuffer->Des();
//Function is leaving at above statement.

iSocket.RecvFrom(p,anAddr,0,iStatus);
Mon, 2006-04-24 08:14
Joined: 2005-11-20
Forum posts: 1246
Re: Problem regarding HBufC
... so then the problem might be your mixup between 8 bit and 16 bit. HBufC is HBufC16, but you use a TPtr8. Try using HBufC8.

René Brunner

Mon, 2006-04-24 08:22
Joined: 2005-03-15
Forum posts: 94
Re: Problem regarding HBufC
It doesn't even compile for me. Probably due to the TPtr8 usage. You should just leave it as TPtr or change the HBufC declaration also as HBufC8.

Vivek Chopra

Vivek Chopra

Mon, 2006-04-24 08:53
Joined: 2006-04-08
Forum posts: 41
Re: Problem regarding HBufC
Quote from: rbrunner
... so then the problem might be your mixup between 8 bit and 16 bit. HBufC is HBufC16, but you use a TPtr8. Try using HBufC8.
I have used HBufC8.
Mon, 2006-04-24 08:59
Joined: 2006-04-08
Forum posts: 41
Re: Problem regarding HBufC
Quote from: vivekchopra
It doesn't even compile for me. Probably due to the TPtr8 usage. You should just leave it as TPtr or change the HBufC declaration also as HBufC8.

Vivek Chopra
I have used HBufC8 n TPtr8, there is no problem of such kind.
Mon, 2006-04-24 09:14
Joined: 2005-08-11
Forum posts: 278
Re: Problem regarding HBufC
It should work. The below code works fine for me:

HBufC8* heapBuf = HBufC8::NewL(10);   
TPtr8 p=heapBuf->Des();

Max_i
Mon, 2006-04-24 10:10
Joined: 2006-04-08
Forum posts: 41
Re: Problem regarding HBufC
Quote from: max_i
It should work. The below code works fine for me:

HBufC8* heapBuf = HBufC8::NewL(10);   
TPtr8 p=heapBuf->Des();

Max_i

It is still not working for me:
when i reach the line :

TPtr8 p=ReadBuffer->Des();
//Function is leaving at above statement.

Debugger gives the following msg at this line:
"Unhandled Exception in euser.dll:0xc0000005:access violation".
Mon, 2006-04-24 12:39
Joined: 2006-04-08
Forum posts: 41
Re: Problem regarding HBufC
Thanx to all...
I have solved my problem with ur valuable suggestions.
Thanx & Regards,
Amit.
  • Login to reply to this topic.