<?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[Libcurl und mehrere Objekte]]></title><description><![CDATA[<p>Angenommen habe ich eine Klasse, in der libcurl verwendet wird um eine Datei aus dem Netz zu laden. Dann muss ich eine Callback angeben:</p>
<pre><code class="language-cpp">Frame* g_mainframe = NULL;

size_t my_curl_write( void *ptr, size_t size, size_t nmemb, void *stream)
{
	if ( g_mainframe != NULL )
	{
		string b((char*)ptr);
		g_mainframe-&gt;TellVersion(b);
		return size*nmemb;
	}
	return size*nmemb;;
}

Frame::Frame()
{
   g_mainframe = this;
}

void Frame::GetHttp()
{
	CURL* curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_URL, &quot;http:/google.de&quot;);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_curl_write);
	if ( curl_easy_perform(curl) != CURLE_OK ) 
	{
		//Böse
	}
	curl_easy_cleanup(curl);
}
</code></pre>
<p>So habe ich es gelöst, da Frame nur 1x existiert, geht es immer an die richtige Adresse. Nur.. wie würde ich das lösen wenn es Frame mehrfach geben würde? Kann man curl iwie nen Zeiger übergeben auf die Instanz?<br />
lg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270132/libcurl-und-mehrere-objekte</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 12:51:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270132.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 Jul 2010 07:04:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Libcurl und mehrere Objekte on Wed, 07 Jul 2010 07:04:32 GMT]]></title><description><![CDATA[<p>Angenommen habe ich eine Klasse, in der libcurl verwendet wird um eine Datei aus dem Netz zu laden. Dann muss ich eine Callback angeben:</p>
<pre><code class="language-cpp">Frame* g_mainframe = NULL;

size_t my_curl_write( void *ptr, size_t size, size_t nmemb, void *stream)
{
	if ( g_mainframe != NULL )
	{
		string b((char*)ptr);
		g_mainframe-&gt;TellVersion(b);
		return size*nmemb;
	}
	return size*nmemb;;
}

Frame::Frame()
{
   g_mainframe = this;
}

void Frame::GetHttp()
{
	CURL* curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_URL, &quot;http:/google.de&quot;);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_curl_write);
	if ( curl_easy_perform(curl) != CURLE_OK ) 
	{
		//Böse
	}
	curl_easy_cleanup(curl);
}
</code></pre>
<p>So habe ich es gelöst, da Frame nur 1x existiert, geht es immer an die richtige Adresse. Nur.. wie würde ich das lösen wenn es Frame mehrfach geben würde? Kann man curl iwie nen Zeiger übergeben auf die Instanz?<br />
lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922530</guid><dc:creator><![CDATA[_libcurler]]></dc:creator><pubDate>Wed, 07 Jul 2010 07:04:32 GMT</pubDate></item><item><title><![CDATA[Reply to Libcurl und mehrere Objekte on Wed, 07 Jul 2010 08:13:20 GMT]]></title><description><![CDATA[<p>Was meinst du damit, dass Frame mehrfach existieren kann?</p>
<p>Ja, man kann der Callback einen Parameter übergeben.</p>
<pre><code class="language-cpp">// [...]
int x = 100;

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_curl_write);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;x);
// [...]
</code></pre>
<pre><code class="language-cpp">size_t my_curl_write( void *ptr, size_t size, size_t nmemb, void  *stream)
{
 int x = (int) stream;
 // [...]
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1922550</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922550</guid><dc:creator><![CDATA[ooooooooo]]></dc:creator><pubDate>Wed, 07 Jul 2010 08:13:20 GMT</pubDate></item><item><title><![CDATA[Reply to Libcurl und mehrere Objekte on Wed, 07 Jul 2010 08:14:15 GMT]]></title><description><![CDATA[<p>Oh, mein Cast ist natürlich falsch, es ist ein int * und kein int. Aber du solltest das Prinzip verstanden haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922552</guid><dc:creator><![CDATA[ooooooooo]]></dc:creator><pubDate>Wed, 07 Jul 2010 08:14:15 GMT</pubDate></item><item><title><![CDATA[Reply to Libcurl und mehrere Objekte on Wed, 07 Jul 2010 20:34:41 GMT]]></title><description><![CDATA[<p>ooooooooo schrieb:</p>
<blockquote>
<p>Oh, mein Cast ist natürlich falsch, es ist ein int * und kein int. Aber du solltest das Prinzip verstanden haben.</p>
</blockquote>
<p>Ja, hab ich. Vielen Dank. Dann übergeb ich da einfach einen Klassenzeiger.<br />
lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922935</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922935</guid><dc:creator><![CDATA[_libcurler]]></dc:creator><pubDate>Wed, 07 Jul 2010 20:34:41 GMT</pubDate></item><item><title><![CDATA[Reply to Libcurl und mehrere Objekte on Thu, 08 Jul 2010 06:19:37 GMT]]></title><description><![CDATA[<p>das ist aber arg unsauber eine downloadfunktionalität so stark mit der gui zu koppeln^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923079</guid><dc:creator><![CDATA[oO]]></dc:creator><pubDate>Thu, 08 Jul 2010 06:19:37 GMT</pubDate></item></channel></rss>