I tried the above method, but it dint work for me. here is the code snippet
"buffer" is TBuf8 type and "temp" is unsigned char*
        counter = buffer.Length(); Mem::Copy(temp, buffer.Ptr(), counter);  //Crashes here
Probably you aren't allocate space for 'temp'. You need some code like:
temp = new(ELeave) unsigned char[counter + 1];
before Mem::Copy() (counter + 1 at minimum, if you copy strings (there must be enought space for data + terminating zero byte!) If this is the case, after Mem::Copy() you must add also:
Why not we discuss in real terms... i think that would give the best understanding.
for example: char str[5];Â // Above statement allocates five continuous bytes (say memory address 100 to 104 if each char takes one byte)
char * ptr; // ptr is pointer variable say it's address is 1000 but content is yet to set ptr=str; // now ptr has the content 100 using ptr we can access and modify array str as following for(TInt i=0;i<5;i++) ptr[i]='a';
Now We should think like above for symbian descriptors TBuf<5>buf;Â //Above should also allocate cont. memory of 10 bytes(So object size is 10 .Right or Wrong?) also buf[i] gives ith character in buffer;
so &buf[0] will be base address; so Is following right char *ptr; ptr=(char *)&buf[0];
Plz have the disscussion to understand the concepts not just how to use them.
Forum posts: 192
Forum posts: 16
but how to conve form TPtrC to char*.
thanks very much!!!
Forum posts: 192
Mem::Copy(pString, ptrc.Ptr(), len);
pString[len] = 0;
and Ptr() function is:
Forum posts: 68
Why isn't there a default constructor for TPtr?
What if you wanted to do something like this:
{
aPtr = _L("blob") ;
}
TPtr ptr ;
method(ptr) ;
// now ptr points to "blob"
The only I can see of doing something similar is like this:
{
aBuf = HBufC16::NewL(4) ;
aBuf->Des() = _L("blob") ;
}
HBufC* buf ;
method(buf) ;
// now buf points to "blob"
Anyone has any better ideas of how do this?
Anyone has a good explanation of why TPtr has no default contructor?
Cheers,
Nikolas.
If we fall down it's so we can learn to pick ourselves up.
Forum posts: 21
I tried the above method, but it dint work for me.
here is the code snippet
"buffer" is TBuf8 type and "temp" is unsigned char*
counter = buffer.Length();
Mem::Copy(temp, buffer.Ptr(), counter); //Crashes here
Any help is highly appreciated.
Forum posts: 1
I tried the above method, but it dint work for me.
here is the code snippet
I test it. It work for me.
http://www.fokle.com
Forum posts: 12
here is the code snippet
"buffer" is TBuf8 type and "temp" is unsigned char*
        counter = buffer.Length();
Mem::Copy(temp, buffer.Ptr(), counter);Â Â //Crashes here
Probably you aren't allocate space for 'temp'. You need some code like:
temp = new(ELeave) unsigned char[counter + 1];
before Mem::Copy()
(counter + 1 at minimum, if you copy strings (there must be enought space for data + terminating zero byte!) If this is the case, after Mem::Copy() you must add also:
temp[counter] = 0;
Forum posts: 11
char *chStr = new char[20];
TBufC8<50> buf8((unsigned char*)chStr);
TBuf16<50> buf16;
buf16.Copy(buf8);
iAppContainer->SetTextL(buf16);
Simple !!!!
Forum posts: 3
funC(const TDesC& ades)
{
char* des= reinterpret_cast<char* > (ades.Ptr());
}
Ptr() converts descriptor to TUint . then u can type cast...
U can avoid reinterpret casting and use c style casting but prefer reinterpret casting...
Forum posts: 3
funC(const TDesC& ades)
{
char* des= reinterpret_cast<char* > (ades.Ptr());
}
Ptr() converts descriptor to TUint . then u can type cast...
U can avoid reinterpret casting and use c style casting but prefer reinterpret casting...
Forum posts: 98
i think that would give the best understanding.
for example:
char str[5];Â
// Above statement allocates five continuous bytes (say memory address 100 to 104 if each char takes one byte)
char * ptr;
// ptr is pointer variable say it's address is 1000 but content is yet to set
ptr=str; // now ptr has the content 100
using ptr we can access and modify array str as following
for(TInt i=0;i<5;i++)
ptr[i]='a';
Now We should think like above for symbian descriptors
TBuf<5>buf;Â
//Above should also allocate cont. memory of 10 bytes(So object size is 10 .Right or Wrong?)
also buf[i] gives ith character in buffer;
so &buf[0] will be base address;
so Is following right
char *ptr;
ptr=(char *)&buf[0];
Plz have the disscussion to understand the concepts not just how to use them.
Forum posts: 4
Mem::Copy(pString, ptrc.Ptr(), len);
pString[len] = 0;
and Ptr() function is:
Forum posts: 276
Now that I have ptr = "aaaa" and buf is an empty 5-chars descriptor, how do I put ptr contents inside buf?
-- JumpJack --
Forum posts: 98
char *str="vikas"; //C Style constant string
char string[6];
TBuf<5>buffer;
strcpy(string,str); // can be used beacuse of estdlib.lib
for(int i=0;i<strlen(str);i++)
buffer.Append(str[i]);
//other option may be buffer.Copy(TUInt16 *(str));
TPtrC& pBody = _L("test source data");
const char* srcData = (const char*)pBody.Ptr();
did try this way too:
const char* srcData= reinterpret_cast<const char*>(pBody.Ptr());
only "t" is being copied into srcData
How can i convert : char dstData[32]; ---> TDesC