Link to home
Start Free TrialLog in
Avatar of becoolnike
becoolnike

asked on

how can i make a plugin and also talk to the host app any source or idea?

how can i make a plugin and also talk to the host app any source or idea?

i want somethig like make a dll app or better called 'plug in' and then

send data to the host and also recieve data .

Avatar of RadikalQ3
RadikalQ3
Flag of Spain image

What kind of plug-in?, a simple function or procedure by example?
You can use a DLL...
ASKER CERTIFIED SOLUTION
Avatar of ZhaawZ
ZhaawZ
Flag of Latvia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It is also possible to call procedure/function from dll if this proc/func is in main application (not only call procs/funcs that are stored in dll).
I think you'll have to 'register' them then. Here's how I do it:

(*---------------- DLL ----------------*)

library Project2;

var
  // Declare variable (this is not a procedure, but it can be used as procedure).
  // This will point to a procedure in main application, so it must have same
  // parameters as proc/func in main app.
  MyProc : procedure (n1, n2 : integer);

// This will be called from main app to 'register' procedure so that it can be used in dll later.
// It needs 'pointer' param. See app source below. After calling this you may use procedure.
procedure RegisterProc(proc : pointer);
begin
MyProc := proc;
end;

// Just a simple proc to test if this works. MyProc can be called from anywhere (after 'registering' it).
procedure CallProc;
begin
MyProc(3, 5);
end;

exports
  RegisterProc, // export procedures for registering proc
  CallProc;     // and for testing if this works

begin
end.


(*---------------- main application ----------------*)
{place a button to form}

unit Unit1;

interface

uses
  Windows, SysUtils, Classes, Forms, Dialogs, Controls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

procedure RegisterProc(proc : pointer); external 'Project2.dll'; // to 'register' proc
procedure CallProc; external 'Project2.dll'; // to call proc (testing)

implementation

{$R *.dfm}

// This is procedure that needs to be called from DLL
procedure TestProc (n1, n2 : integer);
begin
ShowMessage(IntToStr(n1));
ShowMessage(IntToStr(n2));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
// Call RegisterProc to be able to use TestProc from DLL.
// Note that it need pointer as parameter - add @ to the name of proc.
RegisterProc(@TestProc);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
// Testing. Call CallProc from dll and see if it works (CallProc calls TestProc).
CallProc;
end;

end.
Hi!,

For a plug-in is more addecuate link the procedures dinamically, testing if they exists in the especified DLL...
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept ZhaawZ's comment as answer.

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Jacco
EE Cleanup Volunteer