|
|
Classification: |
C++ |
Category: |
Base |
Created: |
10/19/2000 |
Modified: |
09/11/2002 |
Number: |
FAQ-0531 |
Platform: |
Not Applicable |
|
Question: When is calling HBufC::Des() an error?
Answer: The Des() function is often used incorrectly in EPOC code, most commonly with HBufC's:
// a function that reads from aParam void foo(const TDesC& aParam);
void foobarL(){ HBufC* buffer = HBufC::NewL(10); a ten character descriptor.
// ...fill buffer...
foo(buffer->Des()); // call the function that reads from buffer }
The TBufC<> and HBufC classes provide the member function:
TPtr Des();
to enable you to modify the contents of the memory provided by the descriptor. It should be used whenever a modifiable descriptor type is needed that refers to this memory. Whenever a constant descriptor is needed, observe that both TBufC<> and HBufC derive from TDesC, and can therefore be used directly.
So the example above should be:
// a function that reads from aParam void foo(const TDesC& aParam);
void foobarL(){ HBufC* buffer = HBufC::NewL(10); a ten character descriptor.
// ...fill buffer...
foo(*buffer); // call the function that reads from buffer }
|
|
|