<?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[PluginManager Problem]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich habe ein Problem.<br />
Der BCB macht was er will oder ich weiß net was falsch ist.</p>
<p>Erstmal eine Beschreibung was ich vorhabe.<br />
Ich möchte in meinem Programm ermöglichen Plugins zu nutzen.</p>
<p>Ich habe mir vorerst eine Klasse entwickelt die das hand haben soll.</p>
<pre><code class="language-cpp">// Datei: common.h
#ifndef commonH
#define commonH
#include &lt;vcl.h&gt;

typedef struct {
  HINSTANCE   hDLL;
  AnsiString  strPluginFile;
  AnsiString  strPluginName;
  AnsiString  strPluginAuthor;
  AnsiString  strPluginVersion;
} TPluginInfo;

#endif
</code></pre>
<p>Die Klasse TPluginLoader.</p>
<pre><code class="language-cpp">// Datei: TPluginLoader.h
//---------------------------------------------------------------------------

#ifndef TPluginLoaderH
#define TPluginLoaderH
//---------------------------------------------------------------------------
#include &lt;vcl.h&gt;
#include &lt;filectrl.hpp&gt;
#include &quot;..\common.h&quot;
//---------------------------------------------------------------------------
typedef TPluginInfo* (*IMPFUNC)();

class TPluginLoader {
private:
  DynamicArray&lt;TPluginInfo&gt; pPluginData;
  TPluginInfo *pPluginInfo;
  TStrings *pPluginFiles;

  AnsiString strPluginFolder;

  void ScanAfterPlugins(AnsiString strDirName, AnsiString strWildCards,
                        TStrings *sllFileList, bool blNoExtension);
  bool Load(AnsiString PluginFile);
  bool UnloadPlugin(void);
  bool Get_DLL_Info(HINSTANCE DLL);
protected:
public:
  TPluginLoader(AnsiString PluginFolder);
  ~TPluginLoader(void);
  void Scan(void);
};

//---------------------------------------------------------------------------
#endif
</code></pre>
<pre><code class="language-cpp">// Datei: TPluginLoader.cpp
//---------------------------------------------------------------------------

#pragma hdrstop

#include &quot;TPluginLoader.h&quot;

//---------------------------------------------------------------------------

#pragma package(smart_init)

TPluginLoader::TPluginLoader(AnsiString PluginFolder)
{
  this-&gt;pPluginFiles        = new TStringList();
  this-&gt;pPluginData.Length  = 0;
  this-&gt;strPluginFolder     = PluginFolder;
}
//---------------------------------------------------------------------------

TPluginLoader::~TPluginLoader(void)
{
  //TODO: Add your source code here
}
//---------------------------------------------------------------------------

void TPluginLoader::ScanAfterPlugins(AnsiString strDirName,
                                     AnsiString strWildCards,
                                     TStrings *sllFileList,
                                     bool bNoExtension)
{
  TSearchRec stlSearchResult;
  AnsiString strEntry;

  sllFileList-&gt;Clear();

  if(sllFileList != NULL &amp;&amp; strDirName != EmptyStr &amp;&amp; strWildCards != EmptyStr) {
    strDirName  = IncludeTrailingBackslash(strDirName);

    try {
      AnsiString strSearchDir = strDirName + strWildCards;

      if(FindFirst(strSearchDir,faAnyFile,stlSearchResult) == 0) {
        strEntry  = bNoExtension &amp;&amp; stlSearchResult.Name.Length() ?
                    stlSearchResult.Name.SubString(1,stlSearchResult.Name.Length()-
                                                   ExtractFileExt(stlSearchResult.Name).Length()) :
                    stlSearchResult.Name;

        sllFileList-&gt;Add(strEntry);

        while(FindNext(stlSearchResult) == 0) {
          strEntry  = bNoExtension &amp;&amp; stlSearchResult.Name.Length() ?
                      stlSearchResult.Name.SubString(1,stlSearchResult.Name.Length()-
                                                    ExtractFileExt(stlSearchResult.Name).Length()) :
                      stlSearchResult.Name;

          sllFileList-&gt;Add(strEntry);
        } // END OF WHILE

        FindClose(stlSearchResult);
      } // END OF if(FindFirst())
    } // END OF try
    catch(...) { ; }
  } // END OF if(sllFileList !=....)
} // END OF ScanAfter
//---------------------------------------------------------------------------

void TPluginLoader::Scan(void)
{
  this-&gt;ScanAfterPlugins(this-&gt;strPluginFolder,&quot;*.plx&quot;,this-&gt;pPluginFiles,false);
  ShowMessage(&quot;Plugins gefunden: &quot; + AnsiString(this-&gt;pPluginFiles-&gt;Count));
  for(int iIndex = 0;iIndex &lt; this-&gt;pPluginFiles-&gt;Count;iIndex++) {
    this-&gt;Load(this-&gt;pPluginFiles-&gt;Strings[iIndex]);
  }
}
//---------------------------------------------------------------------------

bool TPluginLoader::Load(AnsiString PluginFile)
{
  HINSTANCE DllInstance;

  PluginFile  = this-&gt;strPluginFolder + PluginFile;

  ShowMessage(&quot;Lade Plugin:\n&quot; + PluginFile);

  if(!DllInstance) DllInstance = LoadLibrary(PluginFile.c_str());

  if(DllInstance) {
    if(this-&gt;Get_DLL_Info(DllInstance)) {
      ShowMessage(&quot;Plugin ist richtig...&quot;);

      return true;
    }
    else { ShowMessage(&quot;Plugin ist nicht richtig...&quot;); }
  }
  else { ShowMessage(&quot;Plugin wurde nicht geladen. Es ist ein Fehler aufgetreten!!!&quot;); }

  return false;
}
//---------------------------------------------------------------------------

bool TPluginLoader::UnloadPlugin(void)
{
  return false;
}
//---------------------------------------------------------------------------

bool TPluginLoader::Get_DLL_Info(HINSTANCE DLL)
{
  IMPFUNC DLLFunktion;

  if(this-&gt;pPluginInfo != NULL) {
    this-&gt;pPluginInfo = NULL;
  }

  this-&gt;pPluginInfo = new TPluginInfo;

  if(DLL) {
    DLLFunktion = (IMPFUNC)GetProcAddress(DLL,&quot;_GetInfo&quot;); // Ich habe es auch mal mit GetInfo probiert.

    if(DLLFunktion) {
      /*this-&gt;pPluginInfo =*/ DLLFunktion();

      return true;
    }
    else {
      return false;
    }
  }

  return false;
}
</code></pre>
<p>Im Programm rufe ich einfach die Methode Scan() auf.</p>
<p>-----------------------------------------------------------</p>
<p>Nun zu einem Test-Plugin.<br />
Projekt erstellt mit den Einstellungen:<br />
C++, VCL.</p>
<p>Das PluginCode:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;windows.h&gt;
#include &quot;..\common.h&quot;
#pragma hdrstop
TPluginInfo *PluginInfo;

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
  switch(reason) {
    case DLL_PROCESS_ATTACH:
    ShowMessage(&quot;Die DLL-Datei wurde geladen.&quot;);
    break;

    //-------------------------------------

    case DLL_PROCESS_DETACH:
    ShowMessage(&quot;Die DLL-Datei wurde entladen.&quot;);
    break;
  }

  return 1;
}
//---------------------------------------------------------------------------

extern &quot;C&quot; __declspec(dllexport) TPluginInfo* GetInfo() {
  PluginInfo  = new TPluginInfo;

  PluginInfo-&gt;strPluginName   = &quot;Sound&quot;;
  PluginInfo-&gt;strPluginVersion  = &quot;1.0.0.0&quot;;
  PluginInfo-&gt;strPluginAuthor = &quot;DJ BlackEagle&quot;;

  return PluginInfo;
}
</code></pre>
<p>Jetzt ist die Frage, was ich da falsch mache...</p>
<p>In der Methode &quot;bool TPluginLoader::Get_DLL_Info(HINSTANCE DLL)&quot;<br />
wird ja mit GetProcAddress(), die Adresse der Funktion geholt, aber erhalte immer den Wert NULL.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/118253/pluginmanager-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 19:42:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/118253.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 Aug 2005 17:37:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PluginManager Problem on Tue, 16 Aug 2005 17:37:03 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich habe ein Problem.<br />
Der BCB macht was er will oder ich weiß net was falsch ist.</p>
<p>Erstmal eine Beschreibung was ich vorhabe.<br />
Ich möchte in meinem Programm ermöglichen Plugins zu nutzen.</p>
<p>Ich habe mir vorerst eine Klasse entwickelt die das hand haben soll.</p>
<pre><code class="language-cpp">// Datei: common.h
#ifndef commonH
#define commonH
#include &lt;vcl.h&gt;

typedef struct {
  HINSTANCE   hDLL;
  AnsiString  strPluginFile;
  AnsiString  strPluginName;
  AnsiString  strPluginAuthor;
  AnsiString  strPluginVersion;
} TPluginInfo;

#endif
</code></pre>
<p>Die Klasse TPluginLoader.</p>
<pre><code class="language-cpp">// Datei: TPluginLoader.h
//---------------------------------------------------------------------------

#ifndef TPluginLoaderH
#define TPluginLoaderH
//---------------------------------------------------------------------------
#include &lt;vcl.h&gt;
#include &lt;filectrl.hpp&gt;
#include &quot;..\common.h&quot;
//---------------------------------------------------------------------------
typedef TPluginInfo* (*IMPFUNC)();

class TPluginLoader {
private:
  DynamicArray&lt;TPluginInfo&gt; pPluginData;
  TPluginInfo *pPluginInfo;
  TStrings *pPluginFiles;

  AnsiString strPluginFolder;

  void ScanAfterPlugins(AnsiString strDirName, AnsiString strWildCards,
                        TStrings *sllFileList, bool blNoExtension);
  bool Load(AnsiString PluginFile);
  bool UnloadPlugin(void);
  bool Get_DLL_Info(HINSTANCE DLL);
protected:
public:
  TPluginLoader(AnsiString PluginFolder);
  ~TPluginLoader(void);
  void Scan(void);
};

//---------------------------------------------------------------------------
#endif
</code></pre>
<pre><code class="language-cpp">// Datei: TPluginLoader.cpp
//---------------------------------------------------------------------------

#pragma hdrstop

#include &quot;TPluginLoader.h&quot;

//---------------------------------------------------------------------------

#pragma package(smart_init)

TPluginLoader::TPluginLoader(AnsiString PluginFolder)
{
  this-&gt;pPluginFiles        = new TStringList();
  this-&gt;pPluginData.Length  = 0;
  this-&gt;strPluginFolder     = PluginFolder;
}
//---------------------------------------------------------------------------

TPluginLoader::~TPluginLoader(void)
{
  //TODO: Add your source code here
}
//---------------------------------------------------------------------------

void TPluginLoader::ScanAfterPlugins(AnsiString strDirName,
                                     AnsiString strWildCards,
                                     TStrings *sllFileList,
                                     bool bNoExtension)
{
  TSearchRec stlSearchResult;
  AnsiString strEntry;

  sllFileList-&gt;Clear();

  if(sllFileList != NULL &amp;&amp; strDirName != EmptyStr &amp;&amp; strWildCards != EmptyStr) {
    strDirName  = IncludeTrailingBackslash(strDirName);

    try {
      AnsiString strSearchDir = strDirName + strWildCards;

      if(FindFirst(strSearchDir,faAnyFile,stlSearchResult) == 0) {
        strEntry  = bNoExtension &amp;&amp; stlSearchResult.Name.Length() ?
                    stlSearchResult.Name.SubString(1,stlSearchResult.Name.Length()-
                                                   ExtractFileExt(stlSearchResult.Name).Length()) :
                    stlSearchResult.Name;

        sllFileList-&gt;Add(strEntry);

        while(FindNext(stlSearchResult) == 0) {
          strEntry  = bNoExtension &amp;&amp; stlSearchResult.Name.Length() ?
                      stlSearchResult.Name.SubString(1,stlSearchResult.Name.Length()-
                                                    ExtractFileExt(stlSearchResult.Name).Length()) :
                      stlSearchResult.Name;

          sllFileList-&gt;Add(strEntry);
        } // END OF WHILE

        FindClose(stlSearchResult);
      } // END OF if(FindFirst())
    } // END OF try
    catch(...) { ; }
  } // END OF if(sllFileList !=....)
} // END OF ScanAfter
//---------------------------------------------------------------------------

void TPluginLoader::Scan(void)
{
  this-&gt;ScanAfterPlugins(this-&gt;strPluginFolder,&quot;*.plx&quot;,this-&gt;pPluginFiles,false);
  ShowMessage(&quot;Plugins gefunden: &quot; + AnsiString(this-&gt;pPluginFiles-&gt;Count));
  for(int iIndex = 0;iIndex &lt; this-&gt;pPluginFiles-&gt;Count;iIndex++) {
    this-&gt;Load(this-&gt;pPluginFiles-&gt;Strings[iIndex]);
  }
}
//---------------------------------------------------------------------------

bool TPluginLoader::Load(AnsiString PluginFile)
{
  HINSTANCE DllInstance;

  PluginFile  = this-&gt;strPluginFolder + PluginFile;

  ShowMessage(&quot;Lade Plugin:\n&quot; + PluginFile);

  if(!DllInstance) DllInstance = LoadLibrary(PluginFile.c_str());

  if(DllInstance) {
    if(this-&gt;Get_DLL_Info(DllInstance)) {
      ShowMessage(&quot;Plugin ist richtig...&quot;);

      return true;
    }
    else { ShowMessage(&quot;Plugin ist nicht richtig...&quot;); }
  }
  else { ShowMessage(&quot;Plugin wurde nicht geladen. Es ist ein Fehler aufgetreten!!!&quot;); }

  return false;
}
//---------------------------------------------------------------------------

bool TPluginLoader::UnloadPlugin(void)
{
  return false;
}
//---------------------------------------------------------------------------

bool TPluginLoader::Get_DLL_Info(HINSTANCE DLL)
{
  IMPFUNC DLLFunktion;

  if(this-&gt;pPluginInfo != NULL) {
    this-&gt;pPluginInfo = NULL;
  }

  this-&gt;pPluginInfo = new TPluginInfo;

  if(DLL) {
    DLLFunktion = (IMPFUNC)GetProcAddress(DLL,&quot;_GetInfo&quot;); // Ich habe es auch mal mit GetInfo probiert.

    if(DLLFunktion) {
      /*this-&gt;pPluginInfo =*/ DLLFunktion();

      return true;
    }
    else {
      return false;
    }
  }

  return false;
}
</code></pre>
<p>Im Programm rufe ich einfach die Methode Scan() auf.</p>
<p>-----------------------------------------------------------</p>
<p>Nun zu einem Test-Plugin.<br />
Projekt erstellt mit den Einstellungen:<br />
C++, VCL.</p>
<p>Das PluginCode:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;windows.h&gt;
#include &quot;..\common.h&quot;
#pragma hdrstop
TPluginInfo *PluginInfo;

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
  switch(reason) {
    case DLL_PROCESS_ATTACH:
    ShowMessage(&quot;Die DLL-Datei wurde geladen.&quot;);
    break;

    //-------------------------------------

    case DLL_PROCESS_DETACH:
    ShowMessage(&quot;Die DLL-Datei wurde entladen.&quot;);
    break;
  }

  return 1;
}
//---------------------------------------------------------------------------

extern &quot;C&quot; __declspec(dllexport) TPluginInfo* GetInfo() {
  PluginInfo  = new TPluginInfo;

  PluginInfo-&gt;strPluginName   = &quot;Sound&quot;;
  PluginInfo-&gt;strPluginVersion  = &quot;1.0.0.0&quot;;
  PluginInfo-&gt;strPluginAuthor = &quot;DJ BlackEagle&quot;;

  return PluginInfo;
}
</code></pre>
<p>Jetzt ist die Frage, was ich da falsch mache...</p>
<p>In der Methode &quot;bool TPluginLoader::Get_DLL_Info(HINSTANCE DLL)&quot;<br />
wird ja mit GetProcAddress(), die Adresse der Funktion geholt, aber erhalte immer den Wert NULL.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/853604</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853604</guid><dc:creator><![CDATA[DJ BlackEagle]]></dc:creator><pubDate>Tue, 16 Aug 2005 17:37:03 GMT</pubDate></item><item><title><![CDATA[Reply to PluginManager Problem on Wed, 17 Aug 2005 06:12:58 GMT]]></title><description><![CDATA[<p>Hast du mal in der Schnellansicht nachgesehn, ob GetInfo überhaupt exportiert wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/853817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853817</guid><dc:creator><![CDATA[PuppetMaster2k]]></dc:creator><pubDate>Wed, 17 Aug 2005 06:12:58 GMT</pubDate></item><item><title><![CDATA[Reply to PluginManager Problem on Wed, 17 Aug 2005 09:06:04 GMT]]></title><description><![CDATA[<p>bzw. mit ImpDef mal die Exportnamen angeschaut?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/853964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853964</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 17 Aug 2005 09:06:04 GMT</pubDate></item><item><title><![CDATA[Reply to PluginManager Problem on Wed, 17 Aug 2005 12:30:44 GMT]]></title><description><![CDATA[<p>Ich habe es mit einem HexEditor nach geschaut und da gabs ne Funktion namens _GetInfo.</p>
<p>Ich habe auch mal Impdef gemacht.</p>
<p>Hier mit der Option -a:</p>
<blockquote>
<p>LIBRARY SOUND.PLX</p>
<p>EXPORTS<br />
_GetInfo @1 ; _GetInfo<br />
___CPPdebugHook @2 ; ___CPPdebugHook</p>
</blockquote>
<p>Hier mal mit den Optionen -a -h:</p>
<blockquote>
<p>LIBRARY SOUND.PLX</p>
<p>EXPORTS<br />
_GetInfo @1 @0 ; _GetInfo<br />
___CPPdebugHook @2 @1 ; ___CPPdebugHook</p>
</blockquote>
<p>Und einmal ohne Optionen:</p>
<blockquote>
<p>LIBRARY SOUND.PLX</p>
<p>EXPORTS<br />
_GetInfo @1 ; _GetInfo<br />
___CPPdebugHook @2 ; ___CPPdebugHook</p>
</blockquote>
<p>Also ist der Aufruf mit GetProcAddress(HINSTANCE,&quot;_GetInfo&quot;); richtig.</p>
<p>[edit]Achja, LoadLibrary(PluginFile.c_str()); wird erfolgreich ausgeführt...[/edit]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/854152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/854152</guid><dc:creator><![CDATA[DJ BlackEagle]]></dc:creator><pubDate>Wed, 17 Aug 2005 12:30:44 GMT</pubDate></item><item><title><![CDATA[Reply to PluginManager Problem on Wed, 17 Aug 2005 12:35:34 GMT]]></title><description><![CDATA[<p>Du könnetst mal GetLastError() aufrufen. Evtl steht da noch mehr drin. Ein weiterer Vorschlag ist es mit &quot;GetInfo&quot; statt &quot;_GetInfo&quot; zu probieren, also ohne Unterstrich vor dem Namen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/854175</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/854175</guid><dc:creator><![CDATA[PuppetMaster2k]]></dc:creator><pubDate>Wed, 17 Aug 2005 12:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to PluginManager Problem on Wed, 17 Aug 2005 12:51:54 GMT]]></title><description><![CDATA[<p>wie der Kommentar im Quellcode steht, habe ich es ohne _ versucht. Aber auch ohne erfolg. An der Endung sollte es ja nicht liegen.</p>
<pre><code class="language-cpp">bool TPluginLoader::Get_DLL_Info(HINSTANCE DLL)
{
  IMPFUNC DLLFunktion;

  if(this-&gt;pPluginInfo != NULL) {
    this-&gt;pPluginInfo = NULL;
  }

  this-&gt;pPluginInfo = new TPluginInfo;

  if(DLL) {
    DLLFunktion = (IMPFUNC)GetProcAddress(DLL,&quot;_GetInfo&quot;);
    LPVOID lpMsgBuf;
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                  NULL,
                  GetLastError(),
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                  (LPTSTR) &amp;lpMsgBuf,
                  0,
                  NULL);

    // Display the string.
    MessageBox( NULL, (LPTSTR)lpMsgBuf, &quot;GetLastError&quot;, MB_OK|MB_ICONINFORMATION );

    // Free the buffer.
    LocalFree( lpMsgBuf );

    if(DLLFunktion) {
      /*this-&gt;pPluginInfo =*/ DLLFunktion();

      return true;
    }
    else {
      return false;
    }
  }

  return false;
}
</code></pre>
<p>Die MessageBox sagt mir: &quot;Das angegebene Modul wurde nicht gefunden.&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/854188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/854188</guid><dc:creator><![CDATA[DJ BlackEagle]]></dc:creator><pubDate>Wed, 17 Aug 2005 12:51:54 GMT</pubDate></item></channel></rss>