<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - conversion between char* and  Descriptors - Comments</title>
 <link>http://www.newlc.com/en/topic-9710</link>
 <description>Comments for &quot;conversion between char* and  Descriptors&quot;</description>
 <language>en</language>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46942</link>
 <description>&lt;p&gt;i think u can try this code:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;//if this is character string&lt;br /&gt;char * info = new [ELeave] char[32];&lt;br /&gt;//Use Mem::Copy(..) to copy data to char string&lt;br /&gt;TBuf buffer((unsigned char*)info);//buffer has copied info&amp;#039;s contents&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Mon, 09 Jun 2008 07:47:19 +0200</pubDate>
 <dc:creator>gmsk19</dc:creator>
 <guid isPermaLink="false">comment 46942 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46852</link>
 <description>&lt;p&gt;try my first reply...&lt;/p&gt;</description>
 <pubDate>Wed, 04 Jun 2008 07:38:54 +0200</pubDate>
 <dc:creator>Kerrigan</dc:creator>
 <guid isPermaLink="false">comment 46852 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46836</link>
 <description>&lt;p&gt;&lt;span style=&quot;font-weight:bold&quot;&gt;simple &lt;/span&gt;&lt;br /&gt;
char *&lt;span style=&quot;font-weight:bold&quot;&gt; hexParams&lt;/span&gt; = (char*) malloc(100);&lt;br /&gt;
TInt aLength = strlen(&lt;span style=&quot;font-weight:bold&quot;&gt;hexParams&lt;/span&gt;); ;&lt;br /&gt;
//Convert to Symbian TPtr8 from C  Char * array&lt;br /&gt;
TPtr8 msg2(reinterpret_cast&lt;TUint8*&gt;(&lt;span style=&quot;font-weight:bold&quot;&gt;hexParams&lt;/span&gt;),aLength,aLength);&lt;/p&gt;</description>
 <pubDate>Tue, 03 Jun 2008 13:22:18 +0200</pubDate>
 <dc:creator>praveen.nitdgp@gmail.com</dc:creator>
 <guid isPermaLink="false">comment 46836 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46587</link>
 <description>&lt;p&gt;If you want to copy your literal string to a new buffer, and send it in as a char* I&#039;d recommend this pattern:&lt;/p&gt;

&lt;p&gt;&lt;pre class=&quot;bb-code-block&quot;&gt;
_LIT(KTestData,&quot;test source data&quot;);

RBuf8 buf;
buf.CreateL(KTestData().Length() + 1);

char* charptr = buf.PtrZ();

myfunction(charptr); // ... or whatever...

buf.Close();

&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Then its easy to follow symbian standards in the symbian part of your code.&lt;/p&gt;

&lt;p&gt;If your function is supposed to take over ownership of the char buffer, only then would I recommend using malloc...&lt;/p&gt;

&lt;p&gt;But in that case, I&#039;d recommend simply this:&lt;/p&gt;

&lt;p&gt;&lt;pre class=&quot;bb-code-block&quot;&gt;
_LIT(KTestData,&quot;test source data&quot;);

myfunction(KTestData().Ptr()); // ... or whatever...
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;And let the non-symbian code do the malloc. &lt;/p&gt;

&lt;p&gt;Much better to keep such things collected, and not pollute any file with using dual coding standards in it.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Wed, 28 May 2008 10:06:47 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46587 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46577</link>
 <description>&lt;p&gt;I have a way to do it &lt;br /&gt;
Just try this&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;TPtrC&amp;amp; pBody = _L(&amp;quot;test source data&amp;quot;); &lt;br /&gt;TInt len = pBody .Lenght();&lt;br /&gt;&lt;br /&gt;char*&amp;nbsp; srcData = (char*) malloc(sizeof(char)*len);&lt;br /&gt;&lt;br /&gt;TUint8* ptr = pBody.Ptr();&lt;br /&gt;&lt;br /&gt;for(i=0;i&amp;lt;=len+1;i++)&lt;br /&gt;{&lt;br /&gt;srcData[i] = ptr[i];&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;I think srcData  ll contain the desired result &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 15:19:18 +0200</pubDate>
 <dc:creator>prajwal.r.m</dc:creator>
 <guid isPermaLink="false">comment 46577 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46576</link>
 <description>&lt;p&gt;Hi Nikolas,&lt;/p&gt;

&lt;p&gt;If you are asking to ve a default constructor  for TPtr() it means two things&lt;/p&gt;

&lt;p&gt;1]  You just want a pointer which ll point to some data.No memory allocation is needed (you are not owning it)&lt;br /&gt;
2] And this descriptor is modifiable.&lt;/p&gt;

&lt;p&gt;Now let us take your example.&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;void method (TPtr&amp;amp; aPtr)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; aPtr = _L(&amp;quot;blob&amp;quot;) ;//where the memory is allocated ??&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //and it is modifiable check whether it is supposed to modifiable??&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;TPtr ptr ;&lt;br /&gt;method(ptr) ;&lt;br /&gt;// now ptr points to &amp;quot;blob&amp;quot;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;The memory for _L(&quot;blob&quot;) is allocated on constant data segment which is not supposed to be modified but what is your intension here??&lt;br /&gt;
got it ??&lt;br /&gt;
thats exactly the reason why it is not there &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt; &lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 15:08:49 +0200</pubDate>
 <dc:creator>prajwal.r.m</dc:creator>
 <guid isPermaLink="false">comment 46576 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46575</link>
 <description>&lt;p&gt;If the descriptor is pointing to a string defined in a _LIT(), then the string will already be Zero-terminated.&lt;/p&gt;

&lt;p&gt;If you have in any way copied the string around in descriptor buffers, the zero will have been lost, and you MUST have space in the descriptor buffer and use PtrZ() to write a new Zero  at the end of the buffer.&lt;/p&gt;

&lt;p&gt;This is because the descriptors only copy the number of bytes specified by its Length() and that is specified without the Zero (since descriptors don&#039;t use zero-termination)&lt;br /&gt;
The Zero is already there in the case of _LIT():s because of how C++ work, they will be left there because writing &quot;somestring&quot; in C++ always imply a Zero at the end, but the Zero will in fact be &quot;outside&quot; of space pointet out by the Literal descriptor.&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 14:31:41 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46575 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46395</link>
 <description>&lt;p&gt;Hi RajaRK&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;from descriptor to char*::&lt;/p&gt;

&lt;p&gt;char *q = (char *) ptrC8.Ptr();&lt;br /&gt;
 &lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;
It seems that char* q will not be a null terminated string?? &lt;img src=&quot;/sites/all/modules/smileys/packs/example/shock.png&quot; title=&quot;Shocked&quot; alt=&quot;Shocked&quot; /&gt; &lt;br /&gt;
So it won&#039;t be a C-string.?&lt;/p&gt;</description>
 <pubDate>Sat, 17 May 2008 23:24:44 +0200</pubDate>
 <dc:creator>er.khalid</dc:creator>
 <guid isPermaLink="false">comment 46395 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-46393</link>
 <description>&lt;p&gt;from char* to descriptor::&lt;/p&gt;

&lt;p&gt;char *p = &quot;c string&quot;;&lt;/p&gt;

&lt;p&gt;TPtrC8 ptrC8(p, p-&gt;strlen());&lt;/p&gt;

&lt;p&gt;from descriptor to char*::&lt;/p&gt;

&lt;p&gt;char *q = (char *) ptrC8.Ptr();&lt;/p&gt;</description>
 <pubDate>Sat, 17 May 2008 08:41:35 +0200</pubDate>
 <dc:creator>RajaRK</dc:creator>
 <guid isPermaLink="false">comment 46393 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-23745</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;strlen() is a C function, not C++, not Symbian -&amp;gt; therefore what must you do to the end of the data in the string to turn it into a C string? That&amp;#039;s your answer.&lt;/div&gt;</description>
 <pubDate>Thu, 15 Feb 2007 17:22:05 +0100</pubDate>
 <dc:creator>Fructose</dc:creator>
 <guid isPermaLink="false">comment 23745 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-23744</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&amp;nbsp;Hi&amp;nbsp; all&lt;br /&gt;&lt;br /&gt;&amp;nbsp;ihave a small&amp;nbsp; question &lt;br /&gt;&lt;br /&gt;how to get the&amp;nbsp; length&amp;nbsp; of the&amp;nbsp; unsigned char array?&lt;br /&gt;&lt;br /&gt;I am&amp;nbsp; doing something like this&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;typedef&amp;nbsp; unsigned char&amp;nbsp; hs_uchar&lt;br /&gt;typedef&amp;nbsp; char&amp;nbsp; &amp;nbsp; hs_char&lt;br /&gt;&lt;br /&gt;hs_uchar&amp;nbsp; readbuf[960];&lt;br /&gt;hs_char* temp_string; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now&amp;nbsp; I&amp;nbsp; have&amp;nbsp; one buffer&amp;nbsp; &amp;nbsp;of size&amp;nbsp; &amp;nbsp;320&amp;nbsp; by the name&amp;nbsp; iBufferList[index]&lt;br /&gt;&amp;nbsp;I&amp;nbsp; am&amp;nbsp; doing as follows &lt;br /&gt;&amp;nbsp; temp_string = (hs_char*)read_buf;&lt;br /&gt;&amp;nbsp;memcpy(temp_string, iBufferList.Ptr(),320);&amp;nbsp; &amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;every time I&amp;nbsp; &amp;nbsp;checked the length&amp;nbsp; I&amp;nbsp; got some&amp;nbsp; other numbers&amp;nbsp; but I&amp;nbsp; am expecting&amp;nbsp; a&amp;nbsp; length&amp;nbsp; of&amp;nbsp; 320&amp;nbsp; &amp;nbsp;because&amp;nbsp; iBufferList is&amp;nbsp; of size 320&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;I&amp;nbsp; even tried this method &lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Mem::Copy(readbuf,iBufferList.Ptr(),320);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;TInt len = strlen(readbuf);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;but stilll the same&amp;nbsp; result&amp;nbsp; every time the length&amp;nbsp; is less than&amp;nbsp; 320 sometimes&amp;nbsp; its&amp;nbsp; gives 960 sometimes it gives&amp;nbsp; &amp;nbsp;exact 320&amp;nbsp; &lt;br /&gt;&lt;br /&gt;can any one gives any comments or just tell&amp;nbsp; me how&amp;nbsp; exactly to&amp;nbsp; fine&amp;nbsp; the&amp;nbsp; length of&amp;nbsp; unsigned char array (filled length)&lt;br /&gt;&lt;br /&gt;With Regards&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Thu, 15 Feb 2007 13:05:46 +0100</pubDate>
 <dc:creator>bharatuppal</dc:creator>
 <guid isPermaLink="false">comment 23744 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-23743</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Hey&amp;nbsp; Numpty&amp;nbsp; thanks &lt;br /&gt;&lt;br /&gt;Actually I&amp;nbsp; solved the&amp;nbsp; problem &lt;br /&gt;When&amp;nbsp; I was&amp;nbsp; using&amp;nbsp; the&amp;nbsp; &amp;nbsp; Mem::Copy&amp;nbsp; &amp;nbsp; function &lt;br /&gt;&lt;br /&gt;The&amp;nbsp; address&amp;nbsp; was&amp;nbsp; copied to recdata&amp;nbsp; I&amp;nbsp; debugged the&amp;nbsp; application to&amp;nbsp; check&amp;nbsp; that&lt;br /&gt;&lt;br /&gt;the&amp;nbsp; char string which was passed&amp;nbsp; to my&amp;nbsp; mediarecord&amp;nbsp; function already got that data&amp;nbsp; &amp;nbsp;&lt;br /&gt;&lt;br /&gt; in other words&amp;nbsp; recdata&amp;nbsp; was the reference&lt;br /&gt;&lt;br /&gt;Anyways&amp;nbsp; Thanks&lt;/div&gt;</description>
 <pubDate>Fri, 02 Feb 2007 06:41:44 +0100</pubDate>
 <dc:creator>bharatuppal</dc:creator>
 <guid isPermaLink="false">comment 23743 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-23742</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Have you looked at the contents of recdata? What if the 2nd character is already &amp;#039;\0&amp;#039;? &lt;br /&gt;&lt;br /&gt;I presume tempdata.ptr is a typo? &lt;br /&gt;&lt;br /&gt;How do you know tempdata definatly contains 256 bytes of data?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Thu, 01 Feb 2007 18:18:08 +0100</pubDate>
 <dc:creator>NumptyAlert</dc:creator>
 <guid isPermaLink="false">comment 23742 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-23741</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;following is my&amp;nbsp; scenario &lt;br /&gt;&lt;br /&gt;readmedia(char* recdata, int length)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;TBuf8&amp;lt;260&amp;gt; tempdata;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;readfrommic(tempdata); // readfrommic(TDes8&amp;amp; data) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;so now&amp;nbsp; tempdata&amp;nbsp; gets 256 bytes of data from readfrommic()&lt;br /&gt;&lt;br /&gt;now&amp;nbsp; my problem is I want&amp;nbsp; to&amp;nbsp; give&amp;nbsp; this&amp;nbsp; data&amp;nbsp; &amp;nbsp; to&amp;nbsp; recdata&amp;nbsp; which&amp;nbsp; i&amp;nbsp; character string &lt;br /&gt;&lt;br /&gt;after&amp;nbsp; doing what waas told above&amp;nbsp; &lt;br /&gt;&lt;br /&gt;Mem::Copy(recdata,tempdata.ptr,256);&lt;br /&gt;recdata[257] = 0;&lt;br /&gt;&lt;br /&gt;I&amp;nbsp; called&amp;nbsp; strlen(recdata);&lt;br /&gt;&lt;br /&gt;I got the value as&amp;nbsp; 1&amp;nbsp; &lt;br /&gt;&lt;br /&gt;What is the reason&amp;nbsp; I&amp;nbsp; want&amp;nbsp; the&amp;nbsp; entire&amp;nbsp; tempdata content to be copied to&amp;nbsp; recdata&amp;nbsp; how can&amp;nbsp; I do that&amp;nbsp; &lt;br /&gt;&lt;br /&gt;With Regards&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Thu, 01 Feb 2007 15:52:11 +0100</pubDate>
 <dc:creator>bharatuppal</dc:creator>
 <guid isPermaLink="false">comment 23741 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710#comment-23740</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;standby&amp;nbsp; &amp;nbsp;mark.&lt;/div&gt;</description>
 <pubDate>Mon, 06 Nov 2006 02:31:11 +0100</pubDate>
 <dc:creator>zasdfaaa</dc:creator>
 <guid isPermaLink="false">comment 23740 at http://www.newlc.com</guid>
</item>
<item>
 <title>conversion between char* and  Descriptors</title>
 <link>http://www.newlc.com/en/topic-9710</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/en/topic-9710&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/en/topic-9710#comments</comments>
 <category domain="http://www.newlc.com/en/forums/symbian-c">Symbian C++</category>
 <pubDate>Wed, 10 Aug 2005 11:04:37 +0200</pubDate>
 <dc:creator>jiangzhu20</dc:creator>
 <guid isPermaLink="false">10171 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
