<?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 bei Dll]]></title><description><![CDATA[<p>Hallo, ich bin neu hier aber hab schon ein bisschen erfahrung mit c++.</p>
<p>Mein Problem ist ich hab eine DLL erstellt und diese in mein Test Programm eingebunden , blos nachdem das Programm gestartet ist gibt er mir die Fehlermeldung aus:</p>
<pre><code>Unbehandelte Ausnahme bei 0x641312D3 (Keypress.dll) in TestStation.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x003F0000
</code></pre>
<p>Hier die Header.h in der DLL:</p>
<pre><code>#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

namespace Keypress
{
	class Keypressfunc
	{
	public:

		static __declspec(dllexport) string Presskey(string expstring);

	};
}
</code></pre>
<p>Und die Quelle.cpp der DLL:</p>
<pre><code>#include &quot;Header.h&quot;
#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

namespace Keypress
{
	string Keypressfunc::Presskey(string expstring)
	{
		int lofstr = 0;
		int iofkey = 0;

		lofstr = expstring.length();
		for (iofkey = 0;iofkey &lt; lofstr;iofkey++)
		{
			if (isupper(expstring.at(iofkey)))
			{
				keybd_event(VK_LSHIFT , 0, 0, 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , KEYEVENTF_KEYUP);
				keybd_event(VK_LSHIFT ,0, KEYEVENTF_KEYUP, 0);
			}

			else if (expstring.at(iofkey) == ':')
			{
				keybd_event(VK_LSHIFT , 0, 0, 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , KEYEVENTF_KEYUP);
				keybd_event(VK_LSHIFT ,0, KEYEVENTF_KEYUP, 0);
			}

			else if (expstring.at(iofkey) == '\\')
			{
				keybd_event(VK_LCONTROL,0,0,0);
				keybd_event(VK_LMENU,0,0,0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0,0,0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0,KEYEVENTF_KEYUP,0);
				keybd_event(VK_LMENU,0,KEYEVENTF_KEYUP,0);
				keybd_event(VK_LCONTROL,0,KEYEVENTF_KEYUP,0);
			}

			else
			{
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, KEYEVENTF_KEYUP, 0);
			}
		}
		lofstr = 0;
		iofkey = 0;

		return 0;
	}
}
</code></pre>
<p>Und noch die .cpp vom Test Programm:</p>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;windows.h&gt;
#include &lt;sstream&gt;
#include &quot;Header.h&quot;

using namespace std;
using namespace Keypress;

int _tmain(int argc, _TCHAR* argv[])
{
	string expstring (&quot;Hallo&quot;);

	Sleep(2000);

	Keypressfunc::Presskey(expstring);

	return 0;
}
</code></pre>
<p>so als Anmerkung: Ich arbeite mit MVS 2012.</p>
<p>Ich hoffe ihr könnt mir helfen. <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>Grüsse Benjamin</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313634/unbehandelte-ausnahme-bei-dll</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 03:54:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313634.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Feb 2013 15:52:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unbehandelte Ausnahme bei Dll on Wed, 06 Feb 2013 15:52:00 GMT]]></title><description><![CDATA[<p>Hallo, ich bin neu hier aber hab schon ein bisschen erfahrung mit c++.</p>
<p>Mein Problem ist ich hab eine DLL erstellt und diese in mein Test Programm eingebunden , blos nachdem das Programm gestartet ist gibt er mir die Fehlermeldung aus:</p>
<pre><code>Unbehandelte Ausnahme bei 0x641312D3 (Keypress.dll) in TestStation.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x003F0000
</code></pre>
<p>Hier die Header.h in der DLL:</p>
<pre><code>#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

namespace Keypress
{
	class Keypressfunc
	{
	public:

		static __declspec(dllexport) string Presskey(string expstring);

	};
}
</code></pre>
<p>Und die Quelle.cpp der DLL:</p>
<pre><code>#include &quot;Header.h&quot;
#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

namespace Keypress
{
	string Keypressfunc::Presskey(string expstring)
	{
		int lofstr = 0;
		int iofkey = 0;

		lofstr = expstring.length();
		for (iofkey = 0;iofkey &lt; lofstr;iofkey++)
		{
			if (isupper(expstring.at(iofkey)))
			{
				keybd_event(VK_LSHIFT , 0, 0, 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , KEYEVENTF_KEYUP);
				keybd_event(VK_LSHIFT ,0, KEYEVENTF_KEYUP, 0);
			}

			else if (expstring.at(iofkey) == ':')
			{
				keybd_event(VK_LSHIFT , 0, 0, 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , KEYEVENTF_KEYUP);
				keybd_event(VK_LSHIFT ,0, KEYEVENTF_KEYUP, 0);
			}

			else if (expstring.at(iofkey) == '\\')
			{
				keybd_event(VK_LCONTROL,0,0,0);
				keybd_event(VK_LMENU,0,0,0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0,0,0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0,KEYEVENTF_KEYUP,0);
				keybd_event(VK_LMENU,0,KEYEVENTF_KEYUP,0);
				keybd_event(VK_LCONTROL,0,KEYEVENTF_KEYUP,0);
			}

			else
			{
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, 0 , 0);
				keybd_event(VkKeyScan(expstring.at(iofkey)),0x9e, KEYEVENTF_KEYUP, 0);
			}
		}
		lofstr = 0;
		iofkey = 0;

		return 0;
	}
}
</code></pre>
<p>Und noch die .cpp vom Test Programm:</p>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;windows.h&gt;
#include &lt;sstream&gt;
#include &quot;Header.h&quot;

using namespace std;
using namespace Keypress;

int _tmain(int argc, _TCHAR* argv[])
{
	string expstring (&quot;Hallo&quot;);

	Sleep(2000);

	Keypressfunc::Presskey(expstring);

	return 0;
}
</code></pre>
<p>so als Anmerkung: Ich arbeite mit MVS 2012.</p>
<p>Ich hoffe ihr könnt mir helfen. <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>Grüsse Benjamin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296488</guid><dc:creator><![CDATA[WorldFly]]></dc:creator><pubDate>Wed, 06 Feb 2013 15:52:00 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme bei Dll on Fri, 15 Feb 2013 13:17:44 GMT]]></title><description><![CDATA[<p>So, ich habe ein bisschen experimentiert und herausgefunden das der Fehler definitiv am übertragen des Strings liegt.</p>
<p>Hat jemand eine Idee wie ich den String vernünftig in meine DLL importiere?<br />
Oder kann man einfach kein String importieren?</p>
<p>Grüße Benjamin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299073</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299073</guid><dc:creator><![CDATA[WorldFly]]></dc:creator><pubDate>Fri, 15 Feb 2013 13:17:44 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme bei Dll on Fri, 15 Feb 2013 14:28:31 GMT]]></title><description><![CDATA[<p>Das DLL-Interface sollte möglichst C-Style sein, weil du ansonsten Probleme mit unterschiedlichen Compilern/Compilerversionen bekommen kannst.</p>
<p>Wenn du mit dem selben Compiler die Anwendung kompilierst, mit der die DLL kompiliert wurde, dann ist das in Ordnung. Ansonsten solltest du darüber nachdenken, keine Exceptions durchfliegen zu lassen, exportierte Funktionen mit <em>extern &quot;C&quot;</em> zu schmücken und keine STL oä. im Interface zu verwenden.</p>
<p>Zb. so ...</p>
<pre><code>extern &quot;C&quot; __declspec(dllexport) size_t Keypress_Keypressfunc_Presskey(char const* expstring, char* resultBuffer, size_t bufferLength)
{
    string result = Keypress::Keypressfunc::Presskey(expstring);
    if(result.size() &gt; bufferLength - 1)
        return ERROR_BUFFER_TOO_SMALL;

    size_t copied = result.copy(resultBuffer, bufferLength - 1);
    resultBuffer[copied] = 0;
    return copied;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2299091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299091</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Fri, 15 Feb 2013 14:28:31 GMT</pubDate></item><item><title><![CDATA[Reply to Unbehandelte Ausnahme bei Dll on Fri, 15 Feb 2013 15:43:59 GMT]]></title><description><![CDATA[<p>Ethon schrieb:</p>
<blockquote>
<p>Das DLL-Interface sollte möglichst C-Style sein, weil du ansonsten Probleme mit unterschiedlichen Compilern/Compilerversionen bekommen kannst.</p>
<p>Wenn du mit dem selben Compiler die Anwendung kompilierst, mit der die DLL kompiliert wurde, dann ist das in Ordnung. Ansonsten solltest du darüber nachdenken, keine Exceptions durchfliegen zu lassen, exportierte Funktionen mit <em>extern &quot;C&quot;</em> zu schmücken und keine STL oä. im Interface zu verwenden.</p>
<p>Zb. so ...</p>
<pre><code>extern &quot;C&quot; __declspec(dllexport) size_t Keypress_Keypressfunc_Presskey(char const* expstring, char* resultBuffer, size_t bufferLength)
{
    string result = Keypress::Keypressfunc::Presskey(expstring);
    if(result.size() &gt; bufferLength - 1)
        return ERROR_BUFFER_TOO_SMALL;

    size_t copied = result.copy(resultBuffer, bufferLength - 1);
    resultBuffer[copied] = 0;
    return copied;
}
</code></pre>
</blockquote>
<p>Vielen vielen Dank!! hat mir sehr geholfen, anscheinend kann man ein String bei meiner Lösung einfach nicht übertragen.</p>
<p>Ich poste mal meine Lösung vielleicht ist damit auch Anderen geholfen. <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>Dll Header:</p>
<pre><code>#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

namespace Keypress
{
	class Keypressfunc
	{
	public:

		static __declspec(dllexport) void Presskey(char const* importchar);

	};
}
</code></pre>
<p>Dll cpp:</p>
<pre><code>#include &quot;Header.h&quot;
#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

namespace Keypress
{
	void Keypressfunc::Presskey(char const* importchar)
	{
		string workstr = importchar;
	}
}
</code></pre>
<p>und die cpp vom Programm:</p>
<pre><code>#include &quot;stdafx.h&quot;
#include &quot;Header.h&quot;
#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;

using namespace std;
using namespace Keypress;

int _tmain(int argc, _TCHAR* argv[])
{
	char const* importchar(&quot;Hallo&quot;);

	Keypressfunc::Presskey(importchar);

	return 0;
}
</code></pre>
<p>PS: das mit extern &quot;C&quot; brauche ich im Prinzip nicht da ich immer mit VS 2012 Arbeite, aber trotzdem vielen Dank.</p>
<p>Grüße Benjamin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299140</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299140</guid><dc:creator><![CDATA[WorldFly]]></dc:creator><pubDate>Fri, 15 Feb 2013 15:43:59 GMT</pubDate></item></channel></rss>