Solved

communication beetween dll's and service application, interface

Posted on 2006-10-26
5
568 Views
Last Modified: 2010-08-05
hi experts,
i'm not searching for an source :) just some ideas how to do it different way
the idea is.......
following structure:
        1. service application that cann't be stoped.
        2. the service has an tray icon with an dynamicly loaded menu.
        3. the menuitems cames from dlls that the service is loaded into (service dosn't know the dlls at designtime)
        4. an loaded dll will register all aviable function for export and give the service application acces to.
       
       so any dll have also an list of exportet functions and the structure of variables he needs to execute for the correct running of the function.
       all what the service knows is that the dll must have 2 standart function (exportet)
       1. function init ( var varname: tStringlist ) : Boolean
       2. function execute ( varname: Tstringlist ) : Boolean

      i will explain the communication in the example

example:

     - service is loading the 'main.dll' , and calling the init function
     - the initfunction results his structure in an Tinifile format back to the service with functions like:

        [Internals]
        name=main.dll
        exportetfunctioncount=2
        .....
        [Exportet]
        function1= donothingloop
        function2= dosomthingloop
        [menu]
        item1=donothingloop_item
        item2=dosomthingloop_item
 
     now the service know he cann call 2 functions inside the dll donothingloop and dosomthingloop and service also know he need to add
     2 menu items into systrey menu.

     if the user press now for example "dosomthingloop_item" the service will call the dll function "execute" with the name of the procedure
     the dll have to run.

     there is also a list in the service application with all of the loaded function so other dll's cann also access on

the question now to all of you
     
     do anyone have an idea how to do it in a different way.... maybe there are some components that do such interface options i cann use.
     

i hope all of you understand what i mean, sorry for my english.
0
Comment
Question by:dMa
  • 3
5 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 17811427
well, you can use dynamic loading and standard ini component for reading that config file.
then you will do somethingl ike this: (some kind of pseudo-code follows)

type myfun = function(varname:tstringlist):boolean;
  myfunwrapper=class
    ff:myfun;
  public
    constructor create(f:myfun);
    function callit(varname:tstringlist):boolean;// same prototype as myfun
  end;
constructor myfunwrapper.create;
begin
  ff:=f;
end;

function callit(params):boolean;
begin
  result:=ff(params);
end;

var dll:thandle; i,c:integer; m:TMethod;
begin
  dll:=loadlibrary('main.dll');// replace with ini call to get name value
  c:=inttostr('2');// replace with ini call to get exportetfunctioncount value
  setlength(f,c);
  for i:=1 to c do
  with tmenuitem.create(the menu) do
  begin
    tag:=integer(myfunwrapper.create(getprocaddress(dll,'donothingloop')))// replace with ini call to get function i
    onclick:=myfunwrapper(tag).callit;// and when you free the menuitems, you will iterate through all and call myfunwrapper(tag).free; for each item. this way you don't have to make another variable to keep the references to the wrapper calss ;)
  end;
end;


and that should be all. note that I have written everything directly here and will not compile. but this is the idea that should work right out of the box.
if you don't know how to work with ini files, see this: http://delphi.about.com/od/objectpascalide/l/aa120401a.htm

let me know if you need further guiding or have issues with the idea presented above
0
 
LVL 2

Author Comment

by:dMa
ID: 17811806
thx, that a nice solution how to handle the idea i propose :)
i'm actually searching for an different way how to make the comunication like this.
maybe some kind of plugin manager cann handle that ...do know, maybe there is an easy or more professional way to do.
my idea was to communicate by using tinifiles but actually i'm not so happy with it.

0
 
LVL 28

Expert Comment

by:2266180
ID: 17811855
well, I don't exactl;y see where is the problem of doing the "plugin" yourself :) you could serach for such a plugin but I never stubled across one yet.

If I have time, I can make the function that gets an ini/xml file as input and returns a popupmenu with all needed stuff. I'm just caught up in things and don't know if I can do it in the next few hours. maybe after about 5-6 hours.
other than this function I don't see what else you might need.
0
 
LVL 3

Expert Comment

by:cobi100
ID: 17812836
if you're writing both the service and the dlls, what is you pass the whole Menu to the dll? then you can manipulate the menu from the dlls at your will. so you'll have one single exported function in the dlls called something like RegisterItems(aMenu: TPopupMenu) and there you do something like this:

unit Unit2;

interface
uses
 Menus, Dialogs;

type
  TDllProcMethods = class
    procedure SomeProc(Sender: TObject);
    procedure SomeOtherProc(Sender: TObject);
  end;

var
  DllProcMethods : TDllProcMethods;

procedure InternalRegisterItems(aMenu: TPopupMenu);

implementation

procedure InternalRegisterItems(aMenu: TPopupMenu);
var
  aMenuItem: TMenuItem;
begin
  aMenuItem:= TMenuItem.Create(aMenu);
  aMenuItem.Caption := 'some Caption';
  aMenuItem.OnClick := DllProcMethods.SomeProc;
  aMenu.Items.Add(aMenuItem);
  //Register more menu items here
end;

procedure TDllProcMethods.SomeProc(Sender: TObject);
begin
  //Do something Here
  ShowMessage('some message');
end;

procedure TDllProcMethods.SomeOtherProc(Sender: TObject);
begin
  //Do something Here
end;

end.

In the case above you create your Dll, make sure ShareMem is included on top of the uses list, and use a similar unit to this one, then on your single exported method call the InternalRegisterItems from the unit.
0
 
LVL 28

Accepted Solution

by:
2266180 earned 250 total points
ID: 17812878
found some time and made a small demo: http://www.ciuly.com/delphi/dll_plugin_xml.zip
all you need to do is pass teh xml string to the loadPlugin function and it will return you a popupmenu with all functionality included.
for testing the app, just compile the dll, compile the test app, run the test app, right click on the form and click one of the 2 items.
you can further extend the xml and functionality from this point
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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