<?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[CreateDIBSection Aufruf in einem Thread schlägt fehl]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>ich habe das Problem das ich ein Bild in den Speicher laden muss um dann daraus eine DIB Section zu erstellen.</p>
<p>Das funktioniert auch soweit einwandfrei wenn ich die Funktion zur Erzeugung der DIB Section aus dem Main Thread aufrufe...<br />
wenn ich dies allerdings aus einem neuen Thread heraus mache schlägt die Funktion fehl.</p>
<p>Die Funktion zur Erzeugung der DIB Section sieht wie folgt aus:</p>
<pre><code>HDC			lHdcTemp;
	HBITMAP		lHbmpTemp;
	IPicture	*lPicture;
	long		lWidth;
	long		lHeight;
	long		lWidthPixels;
	long		lHeightPixels;
	GLint		lMaxTexDim;

	HRESULT lHres = OleLoadPicturePath(pPathName, 0, 0, 0, IID_IPicture, (void**)&amp;lPicture);

	if(FAILED(lHres))
	{
		return FALSE;
	}

	lHdcTemp = CreateCompatibleDC(GetDC(NULL));
	if(!lHdcTemp)
	{
		lPicture-&gt;Release();
		return FALSE;
	}

	lPicture-&gt;get_Width(&amp;lWidth);
	lWidthPixels	= MulDiv(lWidth, GetDeviceCaps(lHdcTemp, LOGPIXELSX), 2540);
	lPicture-&gt;get_Height(&amp;lHeight);
	lHeightPixels	= MulDiv(lHeight, GetDeviceCaps(lHdcTemp, LOGPIXELSY), 2540);

	BITMAPINFO	lBitmapInfo		= {0};
	DWORD		*lBitmapBits	= 0;

	lBitmapInfo.bmiHeader.biSize			= sizeof(BITMAPINFOHEADER);
	lBitmapInfo.bmiHeader.biBitCount		= 32;
	lBitmapInfo.bmiHeader.biWidth			= lWidthPixels;
	lBitmapInfo.bmiHeader.biHeight			= lHeightPixels;
	lBitmapInfo.bmiHeader.biCompression		= BI_RGB;
	lBitmapInfo.bmiHeader.biPlanes			= 1;
	lBitmapInfo.bmiHeader.biClrUsed			= 0;
	lBitmapInfo.bmiHeader.biClrImportant	= 0;

	lHbmpTemp = CreateDIBSection(lHdcTemp,
								 &amp;lBitmapInfo,
								 DIB_RGB_COLORS,
								 (void**)&amp;lBitmapBits,
								 NULL,
								 NULL);

	if(!lHbmpTemp)
	{
		DeleteDC(lHdcTemp);
		lPicture-&gt;Release();
		return FALSE;
	}
</code></pre>
<p>Den Thread starte ich mit:</p>
<pre><code>gFLHandle = (HANDLE)_beginthreadex(NULL,
									   0,
									   FmpFrameLoader,
									   (void*)gTexHolder,
									   NULL,
									   NULL);
</code></pre>
<p>Die Frage ist nun, wieso funktioniert alles einwandfrei wenn ich die Funktion so aufrufe<br />
und wieso geht es nicht wenn die Funktion aus dem Thread heraus aufgerufen wird?</p>
<p>Hat darauf irgendwer eine Antwort? Das würde mir sehr weiterhelfen...<br />
Vielen dank schon mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/177943/createdibsection-aufruf-in-einem-thread-schlägt-fehl</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 03:09:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/177943.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Apr 2007 14:55:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CreateDIBSection Aufruf in einem Thread schlägt fehl on Thu, 05 Apr 2007 14:55:07 GMT]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>ich habe das Problem das ich ein Bild in den Speicher laden muss um dann daraus eine DIB Section zu erstellen.</p>
<p>Das funktioniert auch soweit einwandfrei wenn ich die Funktion zur Erzeugung der DIB Section aus dem Main Thread aufrufe...<br />
wenn ich dies allerdings aus einem neuen Thread heraus mache schlägt die Funktion fehl.</p>
<p>Die Funktion zur Erzeugung der DIB Section sieht wie folgt aus:</p>
<pre><code>HDC			lHdcTemp;
	HBITMAP		lHbmpTemp;
	IPicture	*lPicture;
	long		lWidth;
	long		lHeight;
	long		lWidthPixels;
	long		lHeightPixels;
	GLint		lMaxTexDim;

	HRESULT lHres = OleLoadPicturePath(pPathName, 0, 0, 0, IID_IPicture, (void**)&amp;lPicture);

	if(FAILED(lHres))
	{
		return FALSE;
	}

	lHdcTemp = CreateCompatibleDC(GetDC(NULL));
	if(!lHdcTemp)
	{
		lPicture-&gt;Release();
		return FALSE;
	}

	lPicture-&gt;get_Width(&amp;lWidth);
	lWidthPixels	= MulDiv(lWidth, GetDeviceCaps(lHdcTemp, LOGPIXELSX), 2540);
	lPicture-&gt;get_Height(&amp;lHeight);
	lHeightPixels	= MulDiv(lHeight, GetDeviceCaps(lHdcTemp, LOGPIXELSY), 2540);

	BITMAPINFO	lBitmapInfo		= {0};
	DWORD		*lBitmapBits	= 0;

	lBitmapInfo.bmiHeader.biSize			= sizeof(BITMAPINFOHEADER);
	lBitmapInfo.bmiHeader.biBitCount		= 32;
	lBitmapInfo.bmiHeader.biWidth			= lWidthPixels;
	lBitmapInfo.bmiHeader.biHeight			= lHeightPixels;
	lBitmapInfo.bmiHeader.biCompression		= BI_RGB;
	lBitmapInfo.bmiHeader.biPlanes			= 1;
	lBitmapInfo.bmiHeader.biClrUsed			= 0;
	lBitmapInfo.bmiHeader.biClrImportant	= 0;

	lHbmpTemp = CreateDIBSection(lHdcTemp,
								 &amp;lBitmapInfo,
								 DIB_RGB_COLORS,
								 (void**)&amp;lBitmapBits,
								 NULL,
								 NULL);

	if(!lHbmpTemp)
	{
		DeleteDC(lHdcTemp);
		lPicture-&gt;Release();
		return FALSE;
	}
</code></pre>
<p>Den Thread starte ich mit:</p>
<pre><code>gFLHandle = (HANDLE)_beginthreadex(NULL,
									   0,
									   FmpFrameLoader,
									   (void*)gTexHolder,
									   NULL,
									   NULL);
</code></pre>
<p>Die Frage ist nun, wieso funktioniert alles einwandfrei wenn ich die Funktion so aufrufe<br />
und wieso geht es nicht wenn die Funktion aus dem Thread heraus aufgerufen wird?</p>
<p>Hat darauf irgendwer eine Antwort? Das würde mir sehr weiterhelfen...<br />
Vielen dank schon mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1260198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1260198</guid><dc:creator><![CDATA[Moonraker84]]></dc:creator><pubDate>Thu, 05 Apr 2007 14:55:07 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDIBSection Aufruf in einem Thread schlägt fehl on Thu, 05 Apr 2007 16:25:18 GMT]]></title><description><![CDATA[<p>Vielleicht weil COM nicht initialisiert wurde? (CoInitialize)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1260259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1260259</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 05 Apr 2007 16:25:18 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDIBSection Aufruf in einem Thread schlägt fehl on Tue, 10 Apr 2007 10:09:29 GMT]]></title><description><![CDATA[<p>Daran scheint es nicht zu liegen. Ich habe die COM Initialisierung hinzugefügt,<br />
dass Problem besteht aber weiterhin.</p>
<p>Die Funktion CreateDIBSection(...) gibt NULL zurück, allerdings ohne Fehlercode<br />
(GetLastError() gibt alles ok zurück).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1262793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1262793</guid><dc:creator><![CDATA[Moonraker84]]></dc:creator><pubDate>Tue, 10 Apr 2007 10:09:29 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDIBSection Aufruf in einem Thread schlägt fehl on Thu, 19 Apr 2007 17:01:57 GMT]]></title><description><![CDATA[<p>Danke für die Hilfe, ich habe das Problem jetzt gelöst.</p>
<p>Es lag daran das durch einen mir bis jetzt nicht ganz klaren Grund<br />
wohl die Größenangaben in der BITMAPINFO Struktur auf 0 gesetzt wurden.<br />
Dadurch wurde natürlich keine DIB Section erstellt und die Funktion ist ohne<br />
Fehler beendet worden.</p>
<p>Vielen Dank an alle die sich darüber Gedanken gemacht haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269443</guid><dc:creator><![CDATA[Moonraker84]]></dc:creator><pubDate>Thu, 19 Apr 2007 17:01:57 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDIBSection Aufruf in einem Thread schlägt fehl on Thu, 19 Apr 2007 17:14:09 GMT]]></title><description><![CDATA[<p>Du solltest aber noch den via</p>
<pre><code class="language-cpp">GetDC(NULL)
</code></pre>
<p>angeforderten Gerätekontext wieder freigeben mit:</p>
<pre><code class="language-cpp">ReleaseDC(NULL, hdcEntireScreen);
</code></pre>
<p>wobei 'hdcEntireScreen' natürlich von <em>GetDC</em> initialisiert worden ist <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>Wobei ich mir da grad mal auch nicht ganz sicher bin:</p>
<p>MSDN schrieb:</p>
<blockquote>
<p>[...] Class and private DCs do not have to be released. [...]</p>
</blockquote>
<p>Quelle <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_4esj.asp" rel="nofollow">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_4esj.asp</a><br />
Was die hier mit 'Class-DC's' meinen ... <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/1269453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269453</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 19 Apr 2007 17:14:09 GMT</pubDate></item></channel></rss>