<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[new WCHAR]]></title><description><![CDATA[<p>Hallo,<br />
ich versuche gerade utf8 in ansi umzuwandeln.</p>
<p>Ich habe bisher mit folgender Funktion gearbeitet:</p>
<pre><code class="language-cpp">WCHAR w[512];
char m[512];

strcpy(m, utf8text);
MultiByteToWideChar(CP_UTF8, 0, m, -1, w, sizeof(w) / sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, w, -1, m, sizeof(m), 0, 0);

utf8text = m;
</code></pre>
<p>Als ich gerade einen längeren Text umwandeln wollte, habe ich nen Error erhalten, weil der Speicher des Arrays nicht gereicht hat. Also habe ich die Funktion so abgewandelt:</p>
<pre><code class="language-cpp">WCHAR w[512];
char *m = new char[utf8text.GetLength()+1];	

strcpy(m, utf8text);
MultiByteToWideChar(CP_UTF8, 0, m, -1, w, sizeof(w) / sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, w, -1, m, sizeof(m), 0, 0);

utf8text = m;
delete[] m;
</code></pre>
<p>Wenn ich WCHAR auch als dynamisches Array anlege:<br />
WCHAR *w = new WCHAR[utf8text.GetLength()+1];</p>
<p>funktioniert das nicht.<br />
Ich hätte WCHAR aber auch gerne dynamisch.</p>
<p>Wie geht das?</p>
<p>Danke<br />
Miha</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/192845/new-wchar</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 15:30:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/192845.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Sep 2007 11:34:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 11:34:38 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich versuche gerade utf8 in ansi umzuwandeln.</p>
<p>Ich habe bisher mit folgender Funktion gearbeitet:</p>
<pre><code class="language-cpp">WCHAR w[512];
char m[512];

strcpy(m, utf8text);
MultiByteToWideChar(CP_UTF8, 0, m, -1, w, sizeof(w) / sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, w, -1, m, sizeof(m), 0, 0);

utf8text = m;
</code></pre>
<p>Als ich gerade einen längeren Text umwandeln wollte, habe ich nen Error erhalten, weil der Speicher des Arrays nicht gereicht hat. Also habe ich die Funktion so abgewandelt:</p>
<pre><code class="language-cpp">WCHAR w[512];
char *m = new char[utf8text.GetLength()+1];	

strcpy(m, utf8text);
MultiByteToWideChar(CP_UTF8, 0, m, -1, w, sizeof(w) / sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, w, -1, m, sizeof(m), 0, 0);

utf8text = m;
delete[] m;
</code></pre>
<p>Wenn ich WCHAR auch als dynamisches Array anlege:<br />
WCHAR *w = new WCHAR[utf8text.GetLength()+1];</p>
<p>funktioniert das nicht.<br />
Ich hätte WCHAR aber auch gerne dynamisch.</p>
<p>Wie geht das?</p>
<p>Danke<br />
Miha</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368392</guid><dc:creator><![CDATA[miha]]></dc:creator><pubDate>Wed, 19 Sep 2007 11:34:38 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 13:06:47 GMT]]></title><description><![CDATA[<p>Was heißt &quot;funktioniert nicht&quot;? Bei dynamisch angelegten Arrays kannst du mit sizeof() nicht mehr die Größe des Arrays feststellen, da mußt du vorher wissen, wieviel Platz du hast (in dem Fall ist es einfach - die Größe des Feldes steht in utf8text.GetLength()).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368496</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 19 Sep 2007 13:06:47 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 14:19:22 GMT]]></title><description><![CDATA[<p>Es geht nicht um eine nachträgliche Vergrößerung. Ich will die Größe gleich dynamisch anlegen, was aber nicht klappt.</p>
<p>Meldung:<br />
Debug Error!<br />
Programm: ...<br />
DAMAGE: after Normal block (#524) at 0x00397080</p>
<p>Press Retry ...</p>
<p>Bei folgendem Code kommt der Fehler:</p>
<pre><code class="language-cpp">char *m = new char[utf8text.GetLength()+1];	
		WCHAR *w = new WCHAR[utf8text.GetLength()+1];

		strcpy(m, utf8text);
		MultiByteToWideChar(CP_UTF8, 0, m, -1, w, sizeof(w) / sizeof(WCHAR));
		WideCharToMultiByte(CP_ACP, 0, w, -1, m, sizeof(m), 0, 0);

		utf8text = m;

		delete[] m;
		delete[] w;
</code></pre>
<p>Wenn ich WCHAR mit fester Größe 512 anlege, dann kommt kein Fehler.</p>
<p>Grüße,<br />
Michael</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368572</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368572</guid><dc:creator><![CDATA[miha]]></dc:creator><pubDate>Wed, 19 Sep 2007 14:19:22 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 14:21:47 GMT]]></title><description><![CDATA[<p>Wenn ich statt<br />
WCHAR *w = new WCHAR[utf8text.GetLength()+1];<br />
das hier schreibe:<br />
WCHAR *w = new WCHAR[512];<br />
kommt der gleiche Fehler</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368574</guid><dc:creator><![CDATA[miha]]></dc:creator><pubDate>Wed, 19 Sep 2007 14:21:47 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 14:30:11 GMT]]></title><description><![CDATA[<p>Nochmal langsam - deine Art der Größenmessung (sizeof(w)/sizeof(WCHAR)) funktioniert nur für echte Arrays, bei Pointern liefert das nur Müll. Wie groß dein Speicher tatsächlich ist, weißt du aber auch ohne sizeof:</p>
<pre><code class="language-cpp">char *m = new char[utf8text.GetLength()+1];    
WCHAR *w = new WCHAR[utf8text.GetLength()+1];

strcpy(m, utf8text);//Frage: Wozu dient das eigentlich?
MultiByteToWideChar(CP_UTF8, 0, m, -1, w, utf8text.GetLength()+1);
WideCharToMultiByte(CP_ACP, 0, w, -1, m, utf8text.GetLength()+1, 0, 0);

utf8text = m;

delete[] m;
delete[] w;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1368587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368587</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 19 Sep 2007 14:30:11 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 14:59:42 GMT]]></title><description><![CDATA[<p>Suuuuuuuper es klappt!<br />
strcpy(m, utf8text); &lt;= Damit wird der CString in das Char-Array kopiert.</p>
<p>Stimmt daran etwas nicht?<br />
Es wird der Funktion ein CString mit dem zu decodierenden Text übergeben.</p>
<p>Grüße,<br />
Michael</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368617</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368617</guid><dc:creator><![CDATA[miha]]></dc:creator><pubDate>Wed, 19 Sep 2007 14:59:42 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 15:03:59 GMT]]></title><description><![CDATA[<p>miha schrieb:</p>
<blockquote>
<p>Stimmt daran etwas nicht?</p>
</blockquote>
<p>Nicht wirklich, ist imho nur überflüssig - warum gibst du den String nicht direkt an MultiByteToWideChar()?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368621</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 19 Sep 2007 15:03:59 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 15:10:12 GMT]]></title><description><![CDATA[<p>Danke dir!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368631</guid><dc:creator><![CDATA[miha]]></dc:creator><pubDate>Wed, 19 Sep 2007 15:10:12 GMT</pubDate></item><item><title><![CDATA[Reply to new WCHAR on Wed, 19 Sep 2007 15:23:13 GMT]]></title><description><![CDATA[<p>BTW:</p>
<p>wenn du den letzten argument von MultiByteToWideChar auf 0 setzt, wird nichts convertiert, sondern du erhaelst die benoetigte groesse als int</p>
<p>int size = MultiByteToWideChar(CP_UTF8, 0, m, -1, w, 0);<br />
char *m = new char[size];</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1368640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1368640</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Wed, 19 Sep 2007 15:23:13 GMT</pubDate></item></channel></rss>