<?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[&#x27;class CString&#x27; to &#x27;const char *&#x27;, FAQ half nicht]]></title><description><![CDATA[<p>Hi Leute<br />
mein Compiler meckert bei der Zeile:</p>
<pre><code>he=gethostbyname(cs_hostname);
if (he==NULL)
{
dw_Error=WSAGetLastError();
}
</code></pre>
<p>cs_hostname ist ein CString, he ein Pointer auf HOSTENT und dw_Error ein DWORD.<br />
Nun sagt mein Compiler:<br />
error C2664: 'gethostbyname' : cannot convert parameter 1 from 'class CString' to 'const char *'</p>
<p>Ich mein okay, er will eben statt cstring einen char, nun hab ich in der FAQ geschaut (<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39103.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39103.html</a>)<br />
Aber beide Methoden haben nicht funktioniert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<pre><code>he=gethostbyname((LPCTSTR)cs_hostname);
if (he==NULL)
{
dw_Error=WSAGetLastError();	
}
</code></pre>
<p>Fehler:<br />
'gethostbyname' : cannot convert parameter 1 from 'const unsigned short *' to 'const char *'</p>
<p>Kann mir jemand einen Hinweis geben wie ich doch noch den Hostnamen auflösen kann? Ich habe auch schon versucht mit einer Schleife den CString in einen char zu wandeln, aber da war ich mir z.B. nicht sicher ob der das korrekt macht und ob \0 mitkopiert wird, weil der debugger hat da nur Quark ausgegeben.<br />
Gruß Basti</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/195817/class-cstring-to-const-char-faq-half-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 11:49:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195817.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Oct 2007 10:12:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &#x27;class CString&#x27; to &#x27;const char *&#x27;, FAQ half nicht on Mon, 22 Oct 2007 10:12:50 GMT]]></title><description><![CDATA[<p>Hi Leute<br />
mein Compiler meckert bei der Zeile:</p>
<pre><code>he=gethostbyname(cs_hostname);
if (he==NULL)
{
dw_Error=WSAGetLastError();
}
</code></pre>
<p>cs_hostname ist ein CString, he ein Pointer auf HOSTENT und dw_Error ein DWORD.<br />
Nun sagt mein Compiler:<br />
error C2664: 'gethostbyname' : cannot convert parameter 1 from 'class CString' to 'const char *'</p>
<p>Ich mein okay, er will eben statt cstring einen char, nun hab ich in der FAQ geschaut (<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39103.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39103.html</a>)<br />
Aber beide Methoden haben nicht funktioniert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<pre><code>he=gethostbyname((LPCTSTR)cs_hostname);
if (he==NULL)
{
dw_Error=WSAGetLastError();	
}
</code></pre>
<p>Fehler:<br />
'gethostbyname' : cannot convert parameter 1 from 'const unsigned short *' to 'const char *'</p>
<p>Kann mir jemand einen Hinweis geben wie ich doch noch den Hostnamen auflösen kann? Ich habe auch schon versucht mit einer Schleife den CString in einen char zu wandeln, aber da war ich mir z.B. nicht sicher ob der das korrekt macht und ob \0 mitkopiert wird, weil der debugger hat da nur Quark ausgegeben.<br />
Gruß Basti</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389827</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389827</guid><dc:creator><![CDATA[sebastian87]]></dc:creator><pubDate>Mon, 22 Oct 2007 10:12:50 GMT</pubDate></item><item><title><![CDATA[Reply to &#x27;class CString&#x27; to &#x27;const char *&#x27;, FAQ half nicht on Mon, 22 Oct 2007 10:18:48 GMT]]></title><description><![CDATA[<p>gethostbyname() erwartet keinen TCHAR-String, sondern einen char-String. Und für diese Umwandlung gibt es Hilfsmakros wie T2A():</p>
<pre><code class="language-cpp">USES_CONVERSION;//am Anfang der Funktion
...
he=gethostbyname(T2A(cs_hostname));
if (he==NULL)
{
  dw_Error=WSAGetLastError();
}
</code></pre>
<p>PS: Eine Alternative wäre es evt., mit std::string zu arbeiten. (woher bekommst du denn den Hostnamen?)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389829</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 22 Oct 2007 10:18:48 GMT</pubDate></item><item><title><![CDATA[Reply to &#x27;class CString&#x27; to &#x27;const char *&#x27;, FAQ half nicht on Mon, 22 Oct 2007 10:33:49 GMT]]></title><description><![CDATA[<p>danke, werd es gleich mal testen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>und den hostnamen bekomme ich daher:</p>
<pre><code>m_edit_eingabe.GetLine(0, cs_eingabe.GetBuffer(m_edit_eingabe.LineLength(0)),25);
cs_eingabe.ReleaseBuffer();
int i_pos=cs_eingabe.Find(':',0);		
if (i_pos!=0)								
{
cs_hostname=cs_eingabe;
cs_hostname.Delete(i_pos,(i_length - i_pos));
...
</code></pre>
<p>das is also ein CString, der aus einem editfeld kommt<br />
Das dumme is wenn ich jetzt wieder andere Typen verwende bekomm ich wieder probleme mit der Unicode umgebung und und und, mir wurde (hier im Forum) schon empfohlen soweit es möglich ist bei CStrings zu bleiben <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>
<p>//edit:<br />
error C2501: 'USES_CONVERSION' : missing storage-class or type specifiers, wenn es so ziemlich am Anfang der Datei steht und am Anfang der main Funktion gibts den fehler undeclared identifier <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Benutze embedded Visual C++ 4.0, in unicodeumgebung</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389835</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389835</guid><dc:creator><![CDATA[sebastian87]]></dc:creator><pubDate>Mon, 22 Oct 2007 10:33:49 GMT</pubDate></item><item><title><![CDATA[Reply to &#x27;class CString&#x27; to &#x27;const char *&#x27;, FAQ half nicht on Mon, 22 Oct 2007 10:37:36 GMT]]></title><description><![CDATA[<p>sebastian87 schrieb:</p>
<blockquote>
<p>//edit:<br />
error C2501: 'USES_CONVERSION' : missing storage-class or type specifiers<br />
???????????</p>
</blockquote>
<p>Hmm, normalerweise ist USES_CONVERSION ein Hilfsmakro, das einige Variablen für die späteren Stringumwandlungen deklariert - scheint aber nicht in Embedded-Umgebung zu funktionieren. Oder du hast vergessen, den nötigen Header (müsste &lt;ATLCONV.H&gt; sein) einzubinden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389841</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 22 Oct 2007 10:37:36 GMT</pubDate></item><item><title><![CDATA[Reply to &#x27;class CString&#x27; to &#x27;const char *&#x27;, FAQ half nicht on Mon, 22 Oct 2007 12:11:16 GMT]]></title><description><![CDATA[<p>ok danke, hat soweit geklappt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
nur das dumme is jetz, dass er bei<br />
rc=startWinSock(); meldet dass rc==0</p>
<pre><code>int startWinSock(void)
{
	WSADATA wsa;
	return WSAStartup(MAKEWORD(2,0), &amp;wsa);
}
</code></pre>
<p>das is die Funktion dazu, und der restliche Code:</p>
<pre><code>he=gethostbyname(T2A(cs_hostname));
			if (he==NULL)
				{
				dw_Error=WSAGetLastError();
</code></pre>
<p>hier liefert der debugger mir he==NULL und dw_Error ist 10093, was heist dass WSAStartUp() nicht ausgeführt wurde, aber rc==0 sagt mir doch eigentlich genau das Gegenteil?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389908</guid><dc:creator><![CDATA[sebastian87]]></dc:creator><pubDate>Mon, 22 Oct 2007 12:11:16 GMT</pubDate></item></channel></rss>