Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 622
  • Last Modified:

communication beetween dll's and service application, interface

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
dMa
Asked:
dMa
  • 3
1 Solution
 
2266180Commented:
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
 
dMaAuthor Commented:
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
 
2266180Commented:
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
 
cobi100Commented:
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
 
2266180Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now