Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


communication beetween dll's and service application, interface

Posted on 2006-10-26
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: 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

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

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

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.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

598 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