<?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[Anfängerproblem: Kann Funktion aus DLL nicht importieren :(]]></title><description><![CDATA[<p>Hi!</p>
<p>Hab ne DLL geschrieben, die so aussieht:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}

extern &quot;C&quot; __declspec(dllexport) __stdcall unsigned long add(unsigned long a, unsigned long b)
{
  return a+b;
}
</code></pre>
<p>und ne Testfunktion, die so ausschaut:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

typedef unsigned long (*TFunc)(unsigned long, unsigned long);

int main(void)
{
  HINSTANCE hInst = NULL;
  TFunc pAdd = NULL;
  unsigned long a = 2;
  unsigned long b = 3;
  unsigned long res = 0;

  hInst = LoadLibrary(&quot;CDLL.dll&quot;);

  if (hInst)
  {
    cout &lt;&lt; &quot;DLL gefunden&quot; &lt;&lt; endl;

    // Adresse zuweisen
    pAdd = (TFunc)GetProcAddress(hInst,&quot;add&quot;);

    if (pAdd)
    {
      cout &lt;&lt; &quot;2+3=&quot; &lt;&lt; pAdd(a,b) &lt;&lt; endl;
    }
    else
      cerr &lt;&lt; &quot;Zuweisung fehlgeschlagen&quot; &lt;&lt; endl;

    FreeLibrary(hInst);
  }
  else
    cerr &lt;&lt; &quot;DLL nicht gefunden&quot; &lt;&lt; endl;

	return 0;
}
</code></pre>
<p>Leider bekomme ich die Ausgabe:<br />
&quot;DLL gefunden<br />
Zuweisung fehlgeschlagen&quot;</p>
<p>Warum klappt das mit der Zuweisung nicht??? <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 für beide Teile MS Visual .NET, allerdings erstelle ich ne Win32-Konsolenanwendung bzw. ne Win32-DLL.</p>
<p>Danke schonmal an alle helfenden!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/167669/anfängerproblem-kann-funktion-aus-dll-nicht-importieren</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 14:10:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/167669.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 13 Dec 2006 15:44:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfängerproblem: Kann Funktion aus DLL nicht importieren :( on Wed, 13 Dec 2006 15:44:56 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Hab ne DLL geschrieben, die so aussieht:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}

extern &quot;C&quot; __declspec(dllexport) __stdcall unsigned long add(unsigned long a, unsigned long b)
{
  return a+b;
}
</code></pre>
<p>und ne Testfunktion, die so ausschaut:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

typedef unsigned long (*TFunc)(unsigned long, unsigned long);

int main(void)
{
  HINSTANCE hInst = NULL;
  TFunc pAdd = NULL;
  unsigned long a = 2;
  unsigned long b = 3;
  unsigned long res = 0;

  hInst = LoadLibrary(&quot;CDLL.dll&quot;);

  if (hInst)
  {
    cout &lt;&lt; &quot;DLL gefunden&quot; &lt;&lt; endl;

    // Adresse zuweisen
    pAdd = (TFunc)GetProcAddress(hInst,&quot;add&quot;);

    if (pAdd)
    {
      cout &lt;&lt; &quot;2+3=&quot; &lt;&lt; pAdd(a,b) &lt;&lt; endl;
    }
    else
      cerr &lt;&lt; &quot;Zuweisung fehlgeschlagen&quot; &lt;&lt; endl;

    FreeLibrary(hInst);
  }
  else
    cerr &lt;&lt; &quot;DLL nicht gefunden&quot; &lt;&lt; endl;

	return 0;
}
</code></pre>
<p>Leider bekomme ich die Ausgabe:<br />
&quot;DLL gefunden<br />
Zuweisung fehlgeschlagen&quot;</p>
<p>Warum klappt das mit der Zuweisung nicht??? <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 für beide Teile MS Visual .NET, allerdings erstelle ich ne Win32-Konsolenanwendung bzw. ne Win32-DLL.</p>
<p>Danke schonmal an alle helfenden!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1191292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1191292</guid><dc:creator><![CDATA[DLLHell]]></dc:creator><pubDate>Wed, 13 Dec 2006 15:44:56 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem: Kann Funktion aus DLL nicht importieren :( on Thu, 14 Dec 2006 17:48:20 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=18363" rel="nofollow">Jochen Kalmbach</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=58" rel="nofollow">C++/CLI mit .NET</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/1191944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1191944</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Thu, 14 Dec 2006 17:48:20 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem: Kann Funktion aus DLL nicht importieren :( on Fri, 15 Dec 2006 16:13:56 GMT]]></title><description><![CDATA[<p><a href="http://c-plusplus.net/forum/viewtopic-var-p-is-1192550.html#1192550" rel="nofollow">http://c-plusplus.net/forum/viewtopic-var-p-is-1192550.html#1192550</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1192569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1192569</guid><dc:creator><![CDATA[audacia]]></dc:creator><pubDate>Fri, 15 Dec 2006 16:13:56 GMT</pubDate></item></channel></rss>