Solved

DLLS

Posted on 1997-03-23
1
213 Views
Last Modified: 2010-04-04
hi
I'm trying to create a project that use some sort of plugins, in the form of dlls.

Example: if my project is done and running and a month from now I want to
add a feature to it, what I would like to do is just add a plugin(dll).
    What I have done is I create a dll that add a menu to my main program.
(please see the code for the Dll at the in of the Email)
then when I run my main program its load the Dll and the menu item is there.
 This I have done using the external function method.
     But for a real plugin system to work this method will not work for me.
but the Run-Time Method will.
   But I keep getting a memory error when I try this method. if anyone can
find the time to look at my code(which is very small) and perhaps tell me
what I'm doing wrong or were I can get more infomation on this subject I
would appreciate it.

thank you Mike C

--------------- Code for Dll --------------------------------------
uses
  Menus, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs;

type
  TEvent = procedure(Sender: TObject) of object;
  TSomeClass = Class
  procedure DynaClick(Sender: TObject);
end;

 var
  NewMenu : TMenuItem;
  SomeClass : TSomeClass;
  Event : TEvent;

procedure TSomeClass.DynaClick(Sender: TObject);
begin
  showMessage('Its Dll 2');
end;

procedure EntryPoint(AMenu: TMenu); export; stdcall;
var
  NoItem  : TMenuItem;
begin
   //create a event handler...
  SomeClass := TSomeClass.Create;
   //assign Event to DynaClick to be pass to the menu Onclick event...
 Event := SomeClass.DynaClick;

// add new menu to the file menu...

 NoItem := AMenu.Items[AMenu.Items.Count - 1];
 NewMenu := TMenuItem.Create(NoItem);
 NewMenu.Caption := 'DLL2 Menu';
 NewMenu.OnClick := Event;
 NoItem.Insert(NoItem.Count, NewMenu);
 SomeClass.Free;
end;

exports
   EntryPoint;

------------------------ Main Program --------------------------------

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

  type proc = procedure(AMenu:TMenu);

type
    TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    TestLocal1: TMenuItem;
    procedure TestLocal1Click(Sender: TObject);
  private
    { Private declarations }
     myProc : proc;
     Hinst: THandle;
     FPointer: TFarProc;
  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.TestLocal1Click(Sender: TObject);
begin

Hinst :=LoadLibrary('c:\files\mikes\projects\dll\Project1.dll');
if Hinst > 32 then;
   begin
    FPointer := GetProcAddress(Hinst, 'EntryPoint');
      if FPointer <> Nil then
        begin
          MyProc := proc(FPointer);
          try
            MyProc(MainMenu1);;
          except
           FreeLibrary(HInst);
           ShowMessage('Error in Calling EntryPoint Function in DLL');
          end;
       end;
     end;
end;

end.


0
Comment
Question by:mikec459
1 Comment
 
LVL 3

Accepted Solution

by:
sperling earned 100 total points
ID: 1334847
Here's the error...
type proc = procedure(AMenu:TMenu);

Should be:
type proc = procedure(AMenu:TMenu); stdcall;

The declaration you use will make Delphi pass parameters to the function as it would to any other function in your applications code, that is by using registers. However, your DLL expects parameters to be passed on stack (stdcall).

Regards,

Erik.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 304
How to convert wav to mp3 in delphi 9 201
add combobox item based on numbers 9 144
Help on project with Soap 10 54
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question