unit PluginBase;

interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, uPSComponent;

type
  TRegisterPlugin = function(): TPSPlugin; stdcall;

  TPlugins = class
    class procedure DLLPlugins();
  end;

implementation

uses Main;

procedure TPlugins.DLLPlugins();
var
 dllHandle : cardinal;
 searchResult : TSearchRec;
 ExtensionPath: string;
 DLLHandleList: TList<UInt64>;
 method: TRegisterPlugin;
 plugin: TPSPlugin;
begin
  DLLHandleList:= TList<UInt64>.Create;

  ExtensionPath := ExtractFilePath(GetModuleName(HInstance));

  if findfirst(ExtensionPath + '*.dll', faAnyFile, searchResult) = 0 then
  begin
    repeat
      if searchResult.Name = 'mod_pascal.dll' then continue;

      dllHandle := LoadLibrary(PWideChar(ExtensionPath + searchResult.Name));

      @method := GetProcAddress(dllHandle, 'PSPluginCreate') ;
      if Assigned (method) then
      begin
        plugin := method();
        PluginList.Add(plugin);
      end;

      //FreeLibrary(dllHandle) ;
    until FindNext(searchResult) <> 0;
    FindClose(searchResult.FindHandle);
  end;


end;

end.
