communication beetween dll's and service application, interface

Posted on 2006-10-26
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


     - 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:

        function1= donothingloop
        function2= dosomthingloop
     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.
Question by:dMa
  • 3
LVL 28

Expert Comment

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;
    constructor create(f:myfun);
    function callit(varname:tstringlist):boolean;// same prototype as myfun
constructor myfunwrapper.create;

function callit(params):boolean;

var dll:thandle; i,c:integer; m:TMethod;
  dll:=loadlibrary('main.dll');// replace with ini call to get name value
  c:=inttostr('2');// replace with ini call to get exportetfunctioncount value
  for i:=1 to c do
  with tmenuitem.create(the menu) do
    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 ;)

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:

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

Author Comment

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 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.

LVL 28

Expert Comment

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.

Expert Comment

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;

 Menus, Dialogs;

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

  DllProcMethods : TDllProcMethods;

procedure InternalRegisterItems(aMenu: TPopupMenu);


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

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

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


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.
LVL 28

Accepted Solution

2266180 earned 250 total points
ID: 17812878
found some time and made a small demo:
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
URL for downloading Google Chrome for Win XP 2 191
Microsoft Access 97 and Delphi XE2 9 56
shape, triangle, dbctrlgrid 3 17
FMX TEdit KeyUp handler detecting  "enter" key 4 14
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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