Read-only archive of the All About Symbian forum (2001–2013) · About this archive

don't know how to convert HBufC8 type to TDesC type

2 replies · 5,097 views · Started 11 February 2005

Hi,
I am beginner in Symbian.
I don't know how to convert HBufC8 type to TDesC type.

the sample code will look like this.

HBufC8* fileBuf = HBufC8::NewLC(fileSize);
TPtr8 fileBufPtr = fileBuf->Des();
User::LeaveIfError(file.Read(fileBufPtr));
DoSomethingL(fileBuf); // Here i am passing HBufC8 type as argument.

But DoSomethingL() function needs TDesC as argument.
So, i want to convert that HBufC8 type buffer into HBufC16 or TDesC16 or TDesC type. otherwise please help me in converting TPtr8 type into TPtrC type.

Please help me.

Thanks in advance,
Jay.

HBufC8 inherits from TDesC8. So you can simply pass the HBufC8 to any procedure expecting a TDesC8.

I notice you ask about converting HBufC8 to TDesC. TDesC is cast to TDesC8 or TDesC16 depednig on your environment. So if you really want an TDesC8 all is well, if you really want a TDesC16 you need an explicit conversion between asscii and unicode.

Why are you specifiying 8? Better to use the unsized types unless you specifically want Ascii