Pegasus Mail & Mercury

Welcome to the Community for Pegasus Mail and
The Mercury Mail Transport System, the Internet's longest-serving PC e-mail system!
Welcome to Pegasus Mail & Mercury Sign in | Join | Help
in
Home Blogs Forums Downloads Pegasus Mail Overview Mercury Overview

First Daemon

Last post 07-03-2008, 16:59 by Rolf Lindby. 9 replies.
Sort Posts: Previous Next
  •  05-27-2008, 18:06

    • Craig is not online. Last active: 06-18-2008, 12:26 Craig
    • Top 500 Contributor
    • Joined on 05-27-2008
    • Member
    • Points 105

    First Daemon

    Ive been reading some posts on here and reading the daemon.txt file, i checked out the sample and compiled it just to check.

    Im compiling with Code::Blocks 8.02 which uses MinGW compiler

    Unfortunatley im compiling on Vista =) ( which im not to kean on but i remember some time ago having problems compiling with mingw on vista )

    anyway.... it compiles properly and i can get the main entry point to execute ( DLLMAIN; DLL_PROCESS_ATTACH )

    but when i try to get mercury to call  daemon() it tells me theres been a problem calling the DLL   (Using alias   alias- cookie@monster.com      file-   Daemon:mercuryDLL.dll  )

    "an error occured loading the daemon process."

     

    I dont know if you want me to paste the code if you do just let me know il post it.

    I can only assume its how the compiler/link is creating the function names?? i duno

    Any help would be much appricated

     

    Thanks

     

    Craig 

    Filed under:
  •  05-27-2008, 22:17

    Re: First Daemon

    Code is much easier...
    Kind regards / Peter
  •  05-27-2008, 23:54

    Re: First Daemon

    I'm not at all familiar with the compiler you use, but one possible reason for load time crashes for daemons is alignment. Mercury expects Byte alignment, not Word or DWord alignment.

    /Rolf 

  •  05-28-2008, 11:15

    • Craig is not online. Last active: 06-18-2008, 12:26 Craig
    • Top 500 Contributor
    • Joined on 05-27-2008
    • Member
    • Points 105

    Re: First Daemon

    Thanks for the quick reply...

    after some searching i found the proper #pragma command

    #pragma pack(1) 

    so i added that to the daemon.h file at the top, compiled with no problem but same error message when i was trying to run

    i also added it to the main.c file ( just with a slight hope it might help but no luck )

     

    Heres a paste of the main.c file

     

    //
    //  TEMPLATE.C
    //  Basic shell code for a Mercury/32 Daemon Process
    //
    //  Copyright (c) 1997-98, David Harris, All Rights Reserved.
    //

    #pragma pack(1)     /* set alignment to 1 byte boundary */

    //#define STRICT
    #include "main.h"
    #include <stdio.h>
    #include <stdarg.h>

    #define USES_M_INTERFACE
    #include "daemon.h"

    HINSTANCE  hLibInstance;        // set in LibMain, used throughout the DLL
    M_INTERFACE *mi;                // see the note below under "daemon" for this.


    short _export daemon (void *job, M_INTERFACE *m, char *address, char *parameter)
       {
       //  This is the function called by Mercury. Note that we have
       //  created a global variable of type "M_INTERFACE *" called
       //  "mi": doing this allows us to use the "convenience macros"
       //  in DAEMON.H for accessing Mercury internal functions.
       //
       //  At present, the return value from this function is unused
       //  except for Global Daemons (see DAEMON.TXT for more
       //  information on Global Daemons). You should always return
       //  0 from this function by default.

       mi = m;

       if ((mi->vmajor < 2) || ((mi->vmajor == 2) && (mi->vminor < 20)))
          return 0;

       //  Do your daemon processing here.

        FILE *fp = fopen("mercuryDLL.txt", "a+");
        fwrite("> demon\r\n", 9, 1, fp );
        fclose( fp );

       return 0;
       }



    //  DLLEntryPoint is the standard Win32 DLL entry point for the
    //  module. Usually all we do in this function is store our
    //  Instance handle for use in other places, but any reasonable
    //  initialization processing can be done here as well.


    BOOL WINAPI DllEntryPoint (HINSTANCE hInst, DWORD reason, LPVOID reserved)
       {
       //WNDCLASS wc;

       if (reason == DLL_PROCESS_ATTACH)
          hLibInstance = hInst;

       return (TRUE);             // Initialization went OK
       }

     

     

    I also used the template\daemon.h file adding the

    #pragma pack(1)

    command to the top of that too 

     

     

  •  05-28-2008, 21:58

    Re: First Daemon

    Again, I've no idea how your compiler handles this, but maybe you can get some hints from the code to Frans Meijer's forwarding daemon, which he has made available here:

    http://www.xs4all.nl/~fenke/files/

    /Rolf
     

  •  05-29-2008, 11:16

    • Craig is not online. Last active: 06-18-2008, 12:26 Craig
    • Top 500 Contributor
    • Joined on 05-27-2008
    • Member
    • Points 105

    Re: First Daemon

    I tryed compiling that example the other day and still same error message

    Like you said it must be how the compilers compiling it.

    ive also tryed downloading Borland and compiling it with that but no luck i cant get that to compile at all lol

    *my head hurts* 

     

    Thanks for your help anyway, il have a look see and play with it 

  •  06-05-2008, 18:49

    • Craig is not online. Last active: 06-18-2008, 12:26 Craig
    • Top 500 Contributor
    • Joined on 05-27-2008
    • Member
    • Points 105

    Re: First Daemon

    Still not managed to get a project to run properly.

     

    Would it be possible for someone to maybe upload a project with some example code

    maybe recommend a compiler to use too

     

    Sorry to be a pain im just trying to implement a half-ass Domain Keys system

    basically i want to add a header to out going emails with an OpenSSL checksum  of the email.

    I dont think theres a way to add a new header with the returned data from a seperate process executed when the emails receieved?

     

    Thanks

     

    Craig 

  •  06-20-2008, 13:28

    • Thomas Fehr is not online. Last active: 07-07-2008, 1:18 Thomas Fehr
    • Top 200 Contributor
    • Joined on 06-02-2008
    • Switzerland
    • Member
    • Points 245

    Re: First Daemon

    Hi Craig

    Did you finally managed to run your deamon with mercury?


    I've tried with your example above, to make a little deamon
    for learning, but without success.

    I used too Code::Blocks 8.02 to compiling. Compiling
    was ok, but It seems that the deamon never was invoked.
    I've tried also VS 2008 but there I couldn't compile

    I've you or someone has an good experience please
    share it with us Wink

     

     

  •  07-02-2008, 1:18

    Re: First Daemon

    I've used various versions of Borland Delphi for compiling daemons, which has worked good but has the drawback that the daemon.h file needs to be rewritten in Pascal code.

    Again, I'm not familiar with the compiler you have been using. Did you check this? (from daemon.txt):

    If you find that your functions do not seem to be getting called by
    Mercury, check on the format of the name exported by your compiler - this
    is the most likely source of the problem.

    There is actually another way to add a header to any message that goes through Mercury core: by using a policy specifying that message data will be modified by the external program.

    /Rolf 

  •  07-03-2008, 16:59

    Re: First Daemon

    As you may have seen a daemon developer kit was released today, containing lots of new documentation and samples, and revealing the extended daemon API. Hope that will be helpful for you!

    /Rolf
     

View as RSS news feed in XML

Copyright © 2007 David Harris / Peter Strömblad. All Rights Reserved. | Terms of Use | Privacy Statement
Questions/Problems with community.pmail.com? | Visit our Hoster: PraktIT | Pegasus Mail Home Page