Конференция "KOL" » InsertMenu oddities
 
  • Jon © (15.03.11 00:47) [0]
    There seems to be a problem using InsertMenu.

    Using InsertMenu from within a program does not execute the OnClick action (see example below with button DUMMY).

    Using InsertMenu from an external plugin executes incorrect OnClick actions (see example below with button PLUGIN).

    Is this a problem with KOL or just my usage? Simplified source code is below:

    Main app code:


    program mainapp;

    uses
     Messages, Windows, KOL;

    var
     PopupMenu: PMenu;

    procedure ButtonLoadClick(Dummy: Pointer; Sender: PObj);
    var
     Module: HModule;
     PluginMain: procedure(MainPopupMenu: HMenu); stdcall;
    begin
     Module := LoadLibrary(PChar(GetStartDir + 'plugin.dll'));
     if Module <> 0 then
     begin
       ShowMessage('Plugin load: OK');
       PluginMain := GetProcAddress(Module, 'PluginMain');
       if Assigned(PluginMain) then
       begin
         try
           PluginMain(PopupMenu.Handle);
         except
           ShowMessage('Error loading plugin');
         end;
       end;
     end
     else
     begin
       ShowMessage('Plugin load: Error');
     end;
    end;

    procedure DummyItemClick(Dummy: Pointer; Sender: PMenu; Item: Integer);
    begin
     ShowMsg('DUMMY', MB_OK);
    end;

    procedure ButtonDummyClick(Dummy: Pointer; Sender: PObj);
    var
     MyPopup: PMenu;
    begin
     MyPopup := NewMenu(nil, 0, ['xxx', 'yyy', 'zzz'], TOnMenuItem(MakeMethod(nil, @DummyItemClick)));
     InsertMenu(PopupMenu.Handle, 0, MF_BYPOSITION or MF_POPUP, MyPopup.Handle, 'Dummy');
    end;

    procedure MenuItemClick(Dummy: Pointer; Sender: PMenu; Item: Integer);
    begin
     ShowMsg('Count = ' + Int2Str(Sender.Count) + ' : Item = ' + Int2Str(Item) + ' : Text = ' + Sender.ItemText[Item], MB_OK);
    end;

    begin
     Applet := NewForm(nil, 'Test');
     NewMenu(Applet, 0, [], nil);
     PopupMenu := NewMenu(Applet, 0, ['111', '222', '333', '444', '555'], TOnMenuItem(MakeMethod(nil, @MenuItemClick)));
     Applet.SetAutoPopupMenu(PopupMenu);
     with NewButton(Applet,'Load')^ do
       OnClick := TOnEvent(MakeMethod(nil,@ButtonLoadClick));
     with NewButton(Applet,'Dummy').PlaceRight^ do
       OnClick := TOnEvent(MakeMethod(nil,@ButtonDummyClick));
     Run(Applet);
    end.



    Plugin code:


    library plugin;

    uses
     Messages, Windows, KOL;

    procedure MenuItemClick(Dummy: Pointer; Sender: PMenu; Item: Integer);
    begin
     ShowMsg('PLUGIN', MB_OK);
    end;

    procedure PluginMain(MainPopupMenu: HMenu); stdcall;
    var
     MyPopup: PMenu;
    begin
     MyPopup := NewMenu(nil, 0, ['xxx', 'yyy', 'zzz'], TOnMenuItem(MakeMethod(nil, @MenuItemClick)));
     InsertMenu(MainPopupMenu, 0, MF_BYPOSITION or MF_POPUP, MyPopup.Handle, 'Plugin');
    end;

    exports PluginMain;

    end.

  • Shin (17.03.11 01:05) [1]
    При добавлении uses KOL в библиотеке она перестает загружаться.
    [Windows 7, Delphi 2009, KOL 3.1415926535897]

    Код тестирующей программы:

    program Project1;

    {$APPTYPE CONSOLE}

    uses
     Windows, Messages, KOL;

    var
     Module: HMODULE;
     Check: function(): Integer; stdcall;

    begin
     Module := LoadLibrary( PAnsiChar(GetStartDir + 'test.dll') );
     if Module <> 0 then
     begin
       @Check := GetProcAddress(Module, 'Check');
       if Assigned(Check) then
         Writeln( Check() );
       FreeLibrary(Module);
     end;
     Readln;
    end.



    Код библиотеки:

    library test;

    uses
     Windows, KOL;

    function Check(): Integer; stdcall;
    begin
     Result := 132;
    end;

    exports
     Check;

    end.

  • Jon © (17.03.11 02:12) [2]
    No problem with: Windows XP, Delphi 7, KOL 3.1415926535897
    Permissions problem? Try with Delphi: Run As Administrator.
 
Конференция "KOL" » InsertMenu oddities
Есть новые Нет новых   [134430   +4][b:0][p:0.002]