<?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[Wieso wird diese Funktion nicht gefunden?]]></title><description><![CDATA[<p>huhu<br />
ich habe eine funktion in einer dll:<br />
dll.h</p>
<pre><code class="language-cpp">#ifdef __DLLFILE_H
#define __DLLFILE_H

#ifdef BUILDDLL
 #define DLL_MODE
 	__declspec(dllexport)
#else
 #ifdef BUILDAPP
  #define DLL_MODE
        __declspec(dllimport)
  #endif
 #endif

 extern &quot;C&quot;
 int DLL_MODE MyFunction();

 #endif
</code></pre>
<p>dll.cpp</p>
<pre><code class="language-cpp">pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
	return 1;
}
//---------------------------------------------------------------------------
int MyFunction()
{
    return 10;
}
</code></pre>
<p>Calling-Application</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#pragma hdrstop
#define BUILDAPP
#include &quot;Calling_App.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE h = LoadLibrary(&quot;Project1.dll&quot;);
typedef int (*pfunc)();
pfunc myFunc;
if(h!=NULL)
   {
       myFunc = (pfunc)GetProcAddress(h,&quot;_MyFunction&quot;);
       if(myFunc!=NULL)
          {
              int x = myFunc();
              ShowMessage(String(x));
          }
       else
          ShowMessage(&quot;Funktion nicht gefunden&quot;);
   }
else
   ShowMessage(&quot;Datei nicht gefunden&quot;);
}
//-----------------------------------------
</code></pre>
<p>Er sagt mir immer, Funktion nicht gefunden Warum?<br />
Und wie kann ich einen funktionszeiger ohne typedef hier verwenden?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/171997/wieso-wird-diese-funktion-nicht-gefunden</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 06:59:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171997.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 Jan 2007 13:17:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 13:17:31 GMT]]></title><description><![CDATA[<p>huhu<br />
ich habe eine funktion in einer dll:<br />
dll.h</p>
<pre><code class="language-cpp">#ifdef __DLLFILE_H
#define __DLLFILE_H

#ifdef BUILDDLL
 #define DLL_MODE
 	__declspec(dllexport)
#else
 #ifdef BUILDAPP
  #define DLL_MODE
        __declspec(dllimport)
  #endif
 #endif

 extern &quot;C&quot;
 int DLL_MODE MyFunction();

 #endif
</code></pre>
<p>dll.cpp</p>
<pre><code class="language-cpp">pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
	return 1;
}
//---------------------------------------------------------------------------
int MyFunction()
{
    return 10;
}
</code></pre>
<p>Calling-Application</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#pragma hdrstop
#define BUILDAPP
#include &quot;Calling_App.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE h = LoadLibrary(&quot;Project1.dll&quot;);
typedef int (*pfunc)();
pfunc myFunc;
if(h!=NULL)
   {
       myFunc = (pfunc)GetProcAddress(h,&quot;_MyFunction&quot;);
       if(myFunc!=NULL)
          {
              int x = myFunc();
              ShowMessage(String(x));
          }
       else
          ShowMessage(&quot;Funktion nicht gefunden&quot;);
   }
else
   ShowMessage(&quot;Datei nicht gefunden&quot;);
}
//-----------------------------------------
</code></pre>
<p>Er sagt mir immer, Funktion nicht gefunden Warum?<br />
Und wie kann ich einen funktionszeiger ohne typedef hier verwenden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220468</guid><dc:creator><![CDATA[Manager]]></dc:creator><pubDate>Wed, 31 Jan 2007 13:17:31 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 13:49:55 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Deine Funktion ist falsch definiert. Vergleiche mal Deklaration in dll.h mit Definition in dll.cpp.<br />
Wozu brauchst du eigentlich diese dll.h. Beim derzeitigen Stand deiner dll ist die unnötig.<br />
Also<br />
in die dll.cpp muß rein</p>
<pre><code class="language-cpp">extern &quot;C&quot; __declspec(dllexport) int MyFunction()
{
    return 10;
}
</code></pre>
<p>ohne typedef würde das so aussehen.</p>
<pre><code class="language-cpp">int (*myFunc)();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1220501</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220501</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 31 Jan 2007 13:49:55 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 14:02:50 GMT]]></title><description><![CDATA[<p>oh ich dachte ich kann die defines aus der h auch verwenden, also eben dieses DLL_MODE! Geht wohl nicht!</p>
<p>Und zu dem fkt zeiger ohne typedef</p>
<pre><code class="language-cpp">int (*pfunc)();
</code></pre>
<p>und wie benutze ich damit das GetProcAddress?</p>
<pre><code class="language-cpp">int(*pfunc)()GetProcAddress(); //??
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1220511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220511</guid><dc:creator><![CDATA[Manager]]></dc:creator><pubDate>Wed, 31 Jan 2007 14:02:50 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 14:16:19 GMT]]></title><description><![CDATA[<p>So</p>
<pre><code class="language-cpp">myFunc = (int(*)())GetProcAddress();
</code></pre>
<p>Nimm lieber das typedef. Das sieht übersichtlicher aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220518</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 31 Jan 2007 14:16:19 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 14:16:20 GMT]]></title><description><![CDATA[<p>eine frage habe ich gleich noch: Kann ich auch VCL Koponenten (Forms) dynamisch aus einer DLL importieren? (über Funktion dann sicher oder?)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220519</guid><dc:creator><![CDATA[Manager]]></dc:creator><pubDate>Wed, 31 Jan 2007 14:16:20 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 14:21:03 GMT]]></title><description><![CDATA[<p>Ja, das geht auch.<br />
Lies dir doch vielleicht mal ein dll-Tutorial durch<br />
<a href="http://bcb-tutorial.c-plusplus.net/inhalt.html" rel="nofollow">http://bcb-tutorial.c-plusplus.net/inhalt.html</a><br />
oder diesen Thread<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-171798.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-171798.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220523</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 31 Jan 2007 14:21:03 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 14:34:50 GMT]]></title><description><![CDATA[<p>ok, hab das so probiert:<br />
Form.cpp</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit2.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
ShowMessage(Edit1-&gt;Text);	
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &amp;Action)
{
Action = caFree;	
}
</code></pre>
<p>DLL.cpp</p>
<pre><code class="language-cpp">#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
	return 1;
}
//---------------------------------------------------------------------------
extern &quot;C&quot; void __declspec(dllexport) ShowForm(TComponent* Owner)
{
    Form2 = new TForm2(Owner);
    Form2-&gt;ShowModal();
}
</code></pre>
<p>Aufrufendes Programm</p>
<pre><code class="language-cpp">void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE h = LoadLibrary(&quot;Project1.dll&quot;);
if(h)
   {
       typedef void (*pFunc)(TComponent*);
       pFunc CallingFunction;
       CallingFunction = (pFunc)GetProcAddress(h,&quot;_ShowForm&quot;);
       if(CallingFunction)
          {
              CallingFunction(Application);
          }
       else
          {
              ShowMessage(&quot;Form kann nicht angezeigt werden&quot;);
          }
   }
else
   {
       ShowMessage(&quot;Datei nicht gefunden&quot;);
   }
FreeLibrary(h);
}
</code></pre>
<p>öffnet sich alles wunderbar, aber beim schließen der Form aus der DLL, bekomme ich eine Zugriffsverletzung!</p>
<p>Wieso?<br />
Wer oder wo muss ich den speicher freigeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220538</guid><dc:creator><![CDATA[manager]]></dc:creator><pubDate>Wed, 31 Jan 2007 14:34:50 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 14:49:18 GMT]]></title><description><![CDATA[<p>ok, bei ShowModal kann ihc danach gleich ein</p>
<pre><code class="language-cpp">delete Form2;
</code></pre>
<p>ausführen, aber was ist, wenn ich die Form nicht Modal anzeige?<br />
Da kommt der Zugriffsfehler!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220549</guid><dc:creator><![CDATA[Manager]]></dc:creator><pubDate>Wed, 31 Jan 2007 14:49:18 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 14:59:19 GMT]]></title><description><![CDATA[<p>Der Zugriffsfehler hat nichts mit dem delete zu tun. geh doch mal mit dem Debugger durch und schau nach wo der Zugriffsfehler kommt. Du solltest auch deiner dll-Form -Instanz nicht Application mitgeben. Übergib hier einfach 0. Bedenke, dass der Owner für das Löschen der Form zuständig ist.<br />
Also</p>
<pre><code class="language-cpp">extern &quot;C&quot; void __declspec(dllexport) ShowForm()
{
    Form2 = new TForm2(0); // jetzt bist du selbst für dein delete zuständig
    Form2-&gt;ShowModal();
    delete Form2;
}
</code></pre>
<p>Bei nichtmodalen Formen kannst du ja im OnClose-Event der Form Action=caFree setzen. Dann wird die Form beim Schließen aus dem Speicher entfernt. Hier solltest du aber aufpassen, dass du nicht die dll entlädtst wären die entsprechende Form noch zu sehen ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220562</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 31 Jan 2007 14:59:19 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 15:02:31 GMT]]></title><description><![CDATA[<p>ok, es liegt daran, das schon das FreeLibrary kommt, bvor die Form Closed ist!<br />
Wie kann ich das Abfangen, da ja die aufrufende Anwendung von dem Form2 nix weiß!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220564</guid><dc:creator><![CDATA[Manager]]></dc:creator><pubDate>Wed, 31 Jan 2007 15:02:31 GMT</pubDate></item><item><title><![CDATA[Reply to Wieso wird diese Funktion nicht gefunden? on Wed, 31 Jan 2007 15:06:58 GMT]]></title><description><![CDATA[<p>Die einfachste Variante wäre, du entlädst die dll erst wenn du die Hauptanwendung beendest. Eine andere Lösung wäre es der Hauptanwendung mitzuteilen wenn sich die dll-Form schließt. Dies kann man über Windows-Botschaften oder auch eine CallBack-Funktion machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1220567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1220567</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 31 Jan 2007 15:06:58 GMT</pubDate></item></channel></rss>