<?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[Unbehandelte Ausnahme, Access Violation]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine DLL erstellen mit C++ und diese dann aus Visual Basic aufrufen. Meine testdll.cpp sieht so aus:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;string.h&gt;
#include &quot;testdll.h&quot;

#define WINAPI __stdcall

long WINAPI TestBMP (HBITMAP hBmp)
{
	BITMAP bm;
	BITMAP * bm2;
	long row;
	long col;
	long i;
	BYTE bPixel;

	GetObject( hBmp, sizeof(BITMAP), &amp;bm );

	bm2 = new BITMAP;

	bm2-&gt;bmBitsPixel = bm.bmBitsPixel;
	bm2-&gt;bmHeight = bm.bmHeight;
	bm2-&gt;bmPlanes = bm.bmPlanes;
	bm2-&gt;bmType = bm.bmType;
	bm2-&gt;bmWidth = bm.bmWidth;
	bm2-&gt;bmWidthBytes = bm.bmWidthBytes;

	memcpy(bm2-&gt;bmBits,bm.bmBits, bm.bmWidthBytes * bm.bmHeight);

	//weitere Verarbeitung folgt noch

	return (long)hBmp;
}
</code></pre>
<p>die header-datei testdll.h:</p>
<pre><code class="language-cpp">extern &quot;C&quot; __declspec(dllexport) long WINAPI TestBMP (HBITMAP hBmp);
</code></pre>
<p>der Aufruf aus Visual Basic klappt ganz gut, nun kommt aber dieser Fehler:</p>
<blockquote>
<p>Unbehandelte Ausnahme in Testprojekt.exe (TESTDLL.DLL): 0xC0000005: Access Violation.</p>
</blockquote>
<p>bei der Zeile mit memcpy!</p>
<p>Testprojekt.exe ist mein VB Projekt... an diesem sollte es nicht liegen...</p>
<p>ich denke dass die DLL kein Zugriff auf den Speicher hat!? nun wie kann ich dennoch drauf zugreifen? gibt es einen umweg?</p>
<p>Vielen Dank im Voraus<br />
Gruß<br />
Steffen</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/171880/unbehandelte-ausnahme-access-violation</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 00:52:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171880.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Jan 2007 11:09:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unbehandelte Ausnahme, Access Violation on Tue, 30 Jan 2007 11:09:27 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine DLL erstellen mit C++ und diese dann aus Visual Basic aufrufen. Meine testdll.cpp sieht so aus:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;string.h&gt;
#include &quot;testdll.h&quot;

#define WINAPI __stdcall

long WINAPI TestBMP (HBITMAP hBmp)
{
	BITMAP bm;
	BITMAP * bm2;
	long row;
	long col;
	long i;
	BYTE bPixel;

	GetObject( hBmp, sizeof(BITMAP), &amp;bm );

	bm2 = new BITMAP;

	bm2-&gt;bmBitsPixel = bm.bmBitsPixel;
	bm2-&gt;bmHeight = bm.bmHeight;
	bm2-&gt;bmPlanes = bm.bmPlanes;
	bm2-&gt;bmType = bm.bmType;
	bm2-&gt;bmWidth = bm.bmWidth;
	bm2-&gt;bmWidthBytes = bm.bmWidthBytes;

	memcpy(bm2-&gt;bmBits,bm.bmBits, bm.bmWidthBytes * bm.bmHeight);

	//weitere Verarbeitung folgt noch

	return (long)hBmp;
}
</code></pre>
<p>die header-datei testdll.h:</p>
<pre><code class="language-cpp">extern &quot;C&quot; __declspec(dllexport) long WINAPI TestBMP (HBITMAP hBmp);
</code></pre>
<p>der Aufruf aus Visual Basic klappt ganz gut, nun kommt aber dieser Fehler:</p>
<blockquote>
<p>Unbehandelte Ausnahme in Testprojekt.exe (TESTDLL.DLL): 0xC0000005: Access Violation.</p>
</blockquote>
<p>bei der Zeile mit memcpy!</p>
<p>Testprojekt.exe ist mein VB Projekt... an diesem sollte es nicht liegen...</p>
<p>ich denke dass die DLL kein Zugriff auf den Speicher hat!? nun wie kann ich dennoch drauf zugreifen? gibt es einen umweg?</p>
<p>Vielen Dank im Voraus<br />
Gruß<br />
Steffen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1219706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1219706</guid><dc:creator><![CDATA[Steffen82]]></dc:creator><pubDate>Tue, 30 Jan 2007 11:09:27 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme, Access Violation on Tue, 30 Jan 2007 11:29:31 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=403" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=4" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1219713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1219713</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Tue, 30 Jan 2007 11:29:31 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme, Access Violation on Tue, 30 Jan 2007 16:40:13 GMT]]></title><description><![CDATA[<p>debuggen?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1219993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1219993</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Tue, 30 Jan 2007 16:40:13 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme, Access Violation on Wed, 31 Jan 2007 00:35:45 GMT]]></title><description><![CDATA[<p>Warum allokierst Du 'bm2' denn dynamisch ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220256</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 31 Jan 2007 00:35:45 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme, Access Violation on Wed, 31 Jan 2007 08:36:08 GMT]]></title><description><![CDATA[<p>wenn ich</p>
<pre><code class="language-cpp">bm2.bmBits = malloc(bm.bmWidthBytes * bm.bmHeight);
</code></pre>
<p>davor mache dann geht alles <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>aber ich brauche nun das bm2 doch nicht, kann den speicher ja auch direkt ändern...</p>
<p>danke für eure Bemühungen!:)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220320</guid><dc:creator><![CDATA[Steffen82]]></dc:creator><pubDate>Wed, 31 Jan 2007 08:36:08 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme, Access Violation on Wed, 31 Jan 2007 08:41:30 GMT]]></title><description><![CDATA[<p>Steffen82 schrieb:</p>
<blockquote>
<p>wenn ich</p>
<pre><code class="language-cpp">bm2.bmBits = malloc(bm.bmWidthBytes * bm.bmHeight);
</code></pre>
<p>davor mache dann geht alles <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>
</blockquote>
<p>Kein Wunder - wenn du keinen Speicher für die Bits anlegst, zeigt der Zeiger ins Nirvana (und da hast du Glück gehabt, daß er in einen 'verbotenen' Speicherbereich gezeigt hat - im Ernstfall kommt nämlich gar keine Meldung und du zerlegst dir unbemerkt Speicher, den du woanders noch benötigst).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220324</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220324</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 31 Jan 2007 08:41:30 GMT</pubDate></item></channel></rss>