Einzelnen Beitrag anzeigen

jonny

Registriert seit: 15. Dez 2003
235 Beiträge
 
Delphi 7 Enterprise
 
#25

Re: Wie Panel in dll ablegen und bei bedarf laden

  Alt 4. Jan 2005, 23:15
So habe jetzt ein Dyn. Array für die Hadles für die Plugins eingebaut und schon bekomme ich kurz nach dem das Plugin geladen wird und ich die hauptanwendung anklicke eine Zugrifsverletzung?

hier Mein Quellcode:
Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Menus, ElImgFrm;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    popupmenuClose: TMenuItem;
    N1: TMenuItem;
    popupmenuLoadPlugin: TMenuItem;
    opendlgPlugin: TOpenDialog;
    ElImageForm1: TElImageForm;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure popupmenuCloseClick(Sender: TObject);
    procedure popupmenuLoadPluginClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    procedure LoadPlugin(PluginPath: String);
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

type TPluginModule = Record
  Name: String;
  pih: HModule;
end;

var
  Form1: TForm1;
  Plugins: Array of TPluginModule;
implementation

{$R *.dfm}

procedure TForm1.LoadPlugin(PluginPath: String);
var phm: HModule;
    LoadP: procedure (Handle: hwnd; var fHeight: integer);
    NewScrollBox: TScrollBox;
    fHeight: integer;
begin
  phm:=LoadPackage(PluginPath);
  If phm <> 0 Then
  try
    @LoadP:=GetProcAddress(phm, 'LoadMe');
    If Assigned(LoadP) Then
    begin
      NewScrollBox:=TScrollBox.Create(Form1);
      NewScrollBox.parent:=self;
      NewScrollBox.Align:=alTop;
      NewScrollBox.Height:=100;
      LoadP(NewScrollBox.Handle, fHeight);
      NewScrollBox.Height := fHeight;

      SetLength(Plugins, Length(Plugins) + 1);
      Plugins[Length(Plugins)].Name:='';
      Plugins[Length(Plugins)].pih:=phm;
    end
    else
    begin
      ShowMessage ('"LoadMe"-Prozedur nicht gefunden');
    end
  finally
//    UnloadPackage(phm);
  end
  else
    ShowMessage ('Plugin nicht gefunden');
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  UnloadProc: procedure;
  I: Integer;
begin
  If Length(Plugins) > 0 Then
  begin
    For I:=0 To Length(Plugins) Do
    begin
      If Plugins[I].pih <> 0 Then
      begin
        @UnloadProc:=GetProcAddress(Plugins[I].pih, 'GetMeFree');
        If Assigned(UnloadProc) Then
          UnloadProc;
        end;
    end;
  end;
end;

procedure TForm1.popupmenuCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.popupmenuLoadPluginClick(Sender: TObject);
begin
  If opendlgPlugin.Execute Then
  begin
    LoadPlugin(opendlgPlugin.FileName);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SetLength(Plugins, 0);
end;

end.
Hat jemand ne Idee woran das liegen könnte?
  Mit Zitat antworten Zitat