<?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[Konvertierung eines CStrings in einen WideString. Wie?]]></title><description><![CDATA[<p>Hi Leute,<br />
Ich hab hier ein kleines Problem: Ich muss aus einem CString einen WideString machen. Konkret geht es um Dateinamen.<br />
In dem CString steht folgendes: (Byte für Byte)</p>
<blockquote>
<p>83 52 83 73 81 5b 20 81 60 20 55 6e 62 65 6e 61 6e 6e 74 2e 74 78 74</p>
</blockquote>
<p>Herauskommen sollte folgendes:</p>
<blockquote>
<p>B3 30 D4 30 FC 30 20 00 5E FF 20 00 55 00 6E 00 62 00 65 00 6E 00 61 00 6E 00 6E 00 74 00 2E 00 74 00 78 00 74 00</p>
</blockquote>
<p>So mach ich das momentan:</p>
<pre><code class="language-cpp">wchar_t ws[2048];
	for(int j=0;j&lt;src.GetLength();++j)
	{
		ws[j]=BYTE(src[j]);
	}
</code></pre>
<p>src ist die CString-Variable. Bei dem Code kommt natürlich das selbe raus wie schon im CString steht, nur nach jedem Byte eben ein 0-Byte:</p>
<blockquote>
<p>83 00 52 00 83 00 usw</p>
</blockquote>
<p>Hab das aus nem Delphisource:</p>
<pre><code>var
  ws: WideString;
begin
  ws := src;
end;
</code></pre>
<p>Aber in Ermangelung eines WideStrings habe ich mir obige Schleife gebastelt. Bei normalen Buchstaben, die im ASCII-Zeichensatz sind, ist's ja kein Problem, aber z.b. auf japanischen Systemen klappt das ganze nicht mehr.<br />
Ewiglanger Beitrag, ziemlich kurze Frage: Wie bekomm ich die Konvertierung gescheit hin? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/75712/konvertierung-eines-cstrings-in-einen-widestring-wie</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 06:33:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/75712.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Jun 2004 14:59:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 14:59:04 GMT]]></title><description><![CDATA[<p>Hi Leute,<br />
Ich hab hier ein kleines Problem: Ich muss aus einem CString einen WideString machen. Konkret geht es um Dateinamen.<br />
In dem CString steht folgendes: (Byte für Byte)</p>
<blockquote>
<p>83 52 83 73 81 5b 20 81 60 20 55 6e 62 65 6e 61 6e 6e 74 2e 74 78 74</p>
</blockquote>
<p>Herauskommen sollte folgendes:</p>
<blockquote>
<p>B3 30 D4 30 FC 30 20 00 5E FF 20 00 55 00 6E 00 62 00 65 00 6E 00 61 00 6E 00 6E 00 74 00 2E 00 74 00 78 00 74 00</p>
</blockquote>
<p>So mach ich das momentan:</p>
<pre><code class="language-cpp">wchar_t ws[2048];
	for(int j=0;j&lt;src.GetLength();++j)
	{
		ws[j]=BYTE(src[j]);
	}
</code></pre>
<p>src ist die CString-Variable. Bei dem Code kommt natürlich das selbe raus wie schon im CString steht, nur nach jedem Byte eben ein 0-Byte:</p>
<blockquote>
<p>83 00 52 00 83 00 usw</p>
</blockquote>
<p>Hab das aus nem Delphisource:</p>
<pre><code>var
  ws: WideString;
begin
  ws := src;
end;
</code></pre>
<p>Aber in Ermangelung eines WideStrings habe ich mir obige Schleife gebastelt. Bei normalen Buchstaben, die im ASCII-Zeichensatz sind, ist's ja kein Problem, aber z.b. auf japanischen Systemen klappt das ganze nicht mehr.<br />
Ewiglanger Beitrag, ziemlich kurze Frage: Wie bekomm ich die Konvertierung gescheit hin? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/532351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532351</guid><dc:creator><![CDATA[dEUs]]></dc:creator><pubDate>Thu, 03 Jun 2004 14:59:04 GMT</pubDate></item><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 15:39:12 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">CString m_sTarget, m_sNick, m_sMsg;
	m_sTarget=&quot;Hallo&quot;;
	m_sNick = &quot;Jens&quot;;
	m_sMsg = &quot;Hallo&quot;;
    const int MAXLEN = 256;
    wchar_t name[MAXLEN], from[MAXLEN], msg[MAXLEN];

    mbstowcs( name, m_sTarget.GetBuffer(0), MAXLEN );
    name[MAXLEN - 1] = L'\0';
    mbstowcs( from, m_sNick.GetBuffer(0), MAXLEN );
    from[MAXLEN - 1] = L'\0';
    mbstowcs( msg, m_sMsg.GetBuffer(0), MAXLEN );
    msg[MAXLEN - 1] = L'\0';
</code></pre>
<p>Vieleicht hilfts.</p>
<p>Devil</p>
]]></description><link>https://www.c-plusplus.net/forum/post/532380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532380</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Thu, 03 Jun 2004 15:39:12 GMT</pubDate></item><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 15:49:19 GMT]]></title><description><![CDATA[<p>Nein, hilft leider nicht. Das scheint das selbe zu machen wie meine Schleife. Zumindest ist das Ergebnis das selbe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/532395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532395</guid><dc:creator><![CDATA[dEUs]]></dc:creator><pubDate>Thu, 03 Jun 2004 15:49:19 GMT</pubDate></item><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 15:55:17 GMT]]></title><description><![CDATA[<p>hmm.. ist dafür net MultiByteToWideChar da? oder hab ich was falsch verstanden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/532400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532400</guid><dc:creator><![CDATA[CMatt]]></dc:creator><pubDate>Thu, 03 Jun 2004 15:55:17 GMT</pubDate></item><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 16:03:33 GMT]]></title><description><![CDATA[<p>MultiByteToWideChar wird in mbstowcs (=<strong>M</strong>ulti<strong>B</strong>yte<strong>s<strong><strong>To</strong></strong>W</strong>ide<strong>C</strong>har<strong>s</strong> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ) verwendet.<br />
So wie's aussieht hab ich aber die Lösung:</p>
<pre><code class="language-cpp">#ifdef _UNICODE 
	::wcscpy( ws, ( LPCTSTR ) src ); 
#else 
	USES_CONVERSION; 
	::wcscpy( ws, A2W( (LPCTSTR)src ) ); 
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/532414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532414</guid><dc:creator><![CDATA[dEUs]]></dc:creator><pubDate>Thu, 03 Jun 2004 16:03:33 GMT</pubDate></item><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 16:09:50 GMT]]></title><description><![CDATA[<p>A2W --&gt; ... --&gt; AfxA2WHelper</p>
<pre><code class="language-cpp">LPWSTR AFXAPI AfxA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars)
{
	if (lpa == NULL)
		return NULL;
	ASSERT(lpw != NULL);
	// verify that no illegal character present
	// since lpw was allocated based on the size of lpa
	// don''t worry about the number of chars
	lpw[0] = ''\0'';
	VERIFY(MultiByteToWideChar(CP_ACP, 0, lpa, -1, lpw, nChars));
	return lpw;
}
}
</code></pre>
<p>WideCharToMultiByte *hust*<br />
ist das net genau das was wir beiden schon geschieben haben? :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/532422</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532422</guid><dc:creator><![CDATA[CMatt]]></dc:creator><pubDate>Thu, 03 Jun 2004 16:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 16:16:04 GMT]]></title><description><![CDATA[<p>Hum <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /><br />
Komisch. Wenigstens tut die Version im Gegensatz zu allem anderen, was ich probiert hab <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/532427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532427</guid><dc:creator><![CDATA[dEUs]]></dc:creator><pubDate>Thu, 03 Jun 2004 16:16:04 GMT</pubDate></item><item><title><![CDATA[Reply to Konvertierung eines CStrings in einen WideString. Wie? on Thu, 03 Jun 2004 22:00:12 GMT]]></title><description><![CDATA[<p>dEUs schrieb:</p>
<blockquote>
<pre><code class="language-cpp">wchar_t ws[2048];
	for(int j=0;j&lt;src.GetLength();++j)
	{
		ws[j]=BYTE(src[j]);
	}
</code></pre>
</blockquote>
<p>wie wärs mit</p>
<pre><code class="language-cpp">CComBSTR wstr=src;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/532763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/532763</guid><dc:creator><![CDATA[Sovok]]></dc:creator><pubDate>Thu, 03 Jun 2004 22:00:12 GMT</pubDate></item></channel></rss>