Тема: Plugin
Показать сообщение отдельно
  #1  
Старый 05.06.2006, 10:21
ART ART вне форума
Продвинутый
 
Регистрация: 13.02.2006
Адрес: Магнитогорск
Сообщения: 669
Репутация: 14745
По умолчанию Plugin

Есть такая проблема:


-----------------------------Код юнита--------------------------------
unit Unit1;

interface

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

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
PlugList : TStringList;
procedure LoadPlug(fileName : string);
procedure PlugClick(sender : TObject);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.LoadPlug(fileName: string);
var
PlugName : function : PChar;
item : TMenuItem;

handle : THandle;

begin
item := TMenuItem.create(mainMenu1);
handle := LoadLibrary(Pchar(FileName));
if handle <> 0 then
begin
------------И вот здесь вылетает сообщение которое внизу-----------
@PlugName := GetProcAddress(handle,'PluginName'); //Что неправильно?
-----------------------------------------------------------------------
if @PlugName <> nil then
item.caption := PlugName

else
begin
ShowMessage('dll not identifi ');
Exit;
end;
PlugList.Add(FileName);
FreeLibrary(handle);
item.onClick:=PlugClick;
Mainmenu1.items[0].add(item);
end;
end;



procedure TForm1.PlugClick(sender: TObject);
var
PlugExec : function(AObject : TObject): boolean;
PlugType : function: PChar;
FileName : string;
handle : Thandle;
begin
with (sender as TmenuItem) do
filename:= plugList.Strings[MenuIndex];
handle := LoadLibrary(Pchar(FileName)); //Çàãðóæàåì dll
if handle <> 0 then
begin
//-------------Хотя здесь аналогично------------------
@plugExec := GetProcAddress(handle,'PluginExec');
@plugType := GetProcAddress(handle,'PluginType');
//------------------------------------------------------
if PlugType = 'FORM' then
PlugExec(Form1)
else

if PlugType = 'CANVAS' then
PlugExec(Canvas)
else
if PlugType = 'MENU' then
PlugExec(MainMenu1)
else
if PlugType = 'BRUSH' then
PlugExec(Canvas.brush)
else
if PlugType = 'NIL' then
PlugExec(nil);
end;
FreeLibrary(handle);
end;



procedure TForm1.FormCreate(Sender: TObject);
var
SearchRec : TSearchRec;
begin
plugList:=TStringList.create;
if FindFirst('*.dll',faAnyFile, SearchRec) = 0 then
begin
LoadPlug(SearchRec.name);
while FindNext(SearchRec) = 0 do
LoadPlug(SearchRec.name);
FindClose(SearchRec);
end;
canvas.Font.pitch := fpFixed;
canvas.Font.Size := 20;
canvas.Font.Style:= [fsBold];
end;
----------------------------------------------------------------------
----------------------------Код плагина------------------------------
library plug;

uses
SysUtils,
graphics,
Classes,
windows,
shellapi,
forms;

function PluginType : Pchar;
begin
Plugintype := 'CANVAS';
end;
--------------------------------------
function PluginName:Pchar;
begin
Pluginname := 'Plug01';
end;
--------------------------------------

function PluginExec(Canvas:TCanvas):Boolean;
var
x : integer;
y : integer;
i:integer;
begin
for i:=1 to 100000 do begin
randomize;

x:=random(800);
y:=random(500);
canvas.Pixels[x,y]:=clblack;
end;

PluginExec:=True;
end;
{$R *.res}
exports PluginType name 'PluginType';
exports PluginExec name 'PluginExec';
exports PluginName name 'Plug01';
begin
end.
-----------------------------------------------------------------------
Ответить с цитированием