S
snowsky
Unregistered / Unconfirmed
GUEST, unregistred user!
DLL源代码如下:
--------------------Test2.dpr------------------------------
library Test2;
uses
ShareMem, SysUtils, Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
exports
AddTest2;
begin
end.
----------Unit.pas--------------------
unit Unit1;
interface
uses
ShareMem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Menus;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TH = class
Public
Procedure Click(Sender:TObject);
end;
Function AddTest2(ParentMenu:TMenuItem):TMenuItem;export;stdcall;
var
Form1: TForm1;
H: TH;
implementation
{$R *.dfm}
Function AddTest2(ParentMenu:TMenuItem):TMenuItem;
var Menu:TMenuItem;
begin
Menu:=TMenuItem.Create(ParentMenu);
//Menu:=NewItem('测试二',scNone,false,true,H.Click,0,'mTest1');
Menu.Caption:='新测试二';
Menu.Name:='mTest2';
Menu.OnClick:=H.Click;
Menu.Hint:='222';
Result:=Menu;
end;
Procedure TH.Click(Sender:TObject);
begin
ShowMessage('测试二');
end;
initialization
H:=TH.Create;
finalization
H.Free;
end.
---------------------主程序如下-------------------------------
Procedure TForm1.LoadDll(Const FileName:String);
var LibHandle:integer;
PlugProc:TPlugInProc;
str:string;
Menu:TMenuItem;
begin
str:=ExtractFileName(FileName);
str:=Copy(str,1,Length(str)-4);
str:='Add'+str;
LibHandle:=LoadLibrary(PChar(Filename));
if LibHandle<>0 then
begin
PlugProc:=GetProcAddress(LibHandle,PChar(str));
if Assigned(PlugProc)then
begin
Menu:=TMenuItem.Create(Application);
Menu.OnClick:=Hol.Click;
Menu:=PlugProc(n111);
N111.Add(Menu);
end;
end;
end;
问题是:加载一个DLL插件时一切正常,会在主菜单中正常添加一个子菜单,也可以正常
执行DLL中的点击事件,但如果DLL插件为二个时,主菜单也会正常添加二个子菜单,且
Caption也正常,只是点击任意一个子菜单都只会响应第一个子菜单的点击事件。
请高手指点,我已经查过DFW上的几乎所有资料,那个开始用PHOTOSHOP举例的文章就请不要
贴到这了。
--------------------Test2.dpr------------------------------
library Test2;
uses
ShareMem, SysUtils, Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
exports
AddTest2;
begin
end.
----------Unit.pas--------------------
unit Unit1;
interface
uses
ShareMem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Menus;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TH = class
Public
Procedure Click(Sender:TObject);
end;
Function AddTest2(ParentMenu:TMenuItem):TMenuItem;export;stdcall;
var
Form1: TForm1;
H: TH;
implementation
{$R *.dfm}
Function AddTest2(ParentMenu:TMenuItem):TMenuItem;
var Menu:TMenuItem;
begin
Menu:=TMenuItem.Create(ParentMenu);
//Menu:=NewItem('测试二',scNone,false,true,H.Click,0,'mTest1');
Menu.Caption:='新测试二';
Menu.Name:='mTest2';
Menu.OnClick:=H.Click;
Menu.Hint:='222';
Result:=Menu;
end;
Procedure TH.Click(Sender:TObject);
begin
ShowMessage('测试二');
end;
initialization
H:=TH.Create;
finalization
H.Free;
end.
---------------------主程序如下-------------------------------
Procedure TForm1.LoadDll(Const FileName:String);
var LibHandle:integer;
PlugProc:TPlugInProc;
str:string;
Menu:TMenuItem;
begin
str:=ExtractFileName(FileName);
str:=Copy(str,1,Length(str)-4);
str:='Add'+str;
LibHandle:=LoadLibrary(PChar(Filename));
if LibHandle<>0 then
begin
PlugProc:=GetProcAddress(LibHandle,PChar(str));
if Assigned(PlugProc)then
begin
Menu:=TMenuItem.Create(Application);
Menu.OnClick:=Hol.Click;
Menu:=PlugProc(n111);
N111.Add(Menu);
end;
end;
end;
问题是:加载一个DLL插件时一切正常,会在主菜单中正常添加一个子菜单,也可以正常
执行DLL中的点击事件,但如果DLL插件为二个时,主菜单也会正常添加二个子菜单,且
Caption也正常,只是点击任意一个子菜单都只会响应第一个子菜单的点击事件。
请高手指点,我已经查过DFW上的几乎所有资料,那个开始用PHOTOSHOP举例的文章就请不要
贴到这了。