Extension development
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
 

<p>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!</p><p>/Rolf  </p>

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 

<p>Ive been reading some posts on here and reading the daemon.txt file, i checked out the sample and compiled it just to check.</p><p>Im compiling with Code::Blocks 8.02 which uses MinGW compiler</p><p>Unfortunatley im compiling on Vista =) ( which im not to kean on but i remember some time ago having problems compiling with mingw on vista )</p><p>anyway.... it compiles properly and i can get the main entry point to execute ( DLLMAIN; DLL_PROCESS_ATTACH )</p><p>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  ) </p><p><i>"an error occured loading the daemon process."</i></p><p>  I dont know if you want me to paste the code if you do just let me know il post it.</p><p>I can only assume its how the compiler/link is creating the function names?? i duno</p><p>Any help would be much appricated</p><p> </p><p>Thanks</p><p> </p><p>Craig </p>

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 

<p>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.</p><p>/Rolf </p>

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 

 

 

&lt;p&gt;Thanks for the quick reply...&lt;/p&gt;&lt;p&gt;after some searching i found the proper #pragma command&lt;/p&gt;&lt;p&gt;#pragma pack(1)&amp;nbsp;&lt;/p&gt;&lt;p&gt;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&lt;/p&gt;&lt;p&gt;i also added it to the main.c file ( just with a slight hope it might help but no luck )&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Heres a paste of the main.c file&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;// //&amp;nbsp; TEMPLATE.C //&amp;nbsp; Basic shell code for a Mercury/32 Daemon Process // //&amp;nbsp; Copyright (c) 1997-98, David Harris, All Rights Reserved. // #pragma pack(1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* set alignment to 1 byte boundary */ //#define STRICT #include &quot;main.h&quot; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdarg.h&amp;gt; #define USES_M_INTERFACE #include &quot;daemon.h&quot; HINSTANCE&amp;nbsp; hLibInstance;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // set in LibMain, used throughout the DLL M_INTERFACE *mi;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // see the note below under &quot;daemon&quot; for this. short _export daemon (void *job, M_INTERFACE *m, char *address, char *parameter) &amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp; //&amp;nbsp; This is the function called by Mercury. Note that we have &amp;nbsp;&amp;nbsp; //&amp;nbsp; created a global variable of type &quot;M_INTERFACE *&quot; called &amp;nbsp;&amp;nbsp; //&amp;nbsp; &quot;mi&quot;: doing this allows us to use the &quot;convenience macros&quot; &amp;nbsp;&amp;nbsp; //&amp;nbsp; in DAEMON.H for accessing Mercury internal functions. &amp;nbsp;&amp;nbsp; // &amp;nbsp;&amp;nbsp; //&amp;nbsp; At present, the return value from this function is unused &amp;nbsp;&amp;nbsp; //&amp;nbsp; except for Global Daemons (see DAEMON.TXT for more &amp;nbsp;&amp;nbsp; //&amp;nbsp; information on Global Daemons). You should always return &amp;nbsp;&amp;nbsp; //&amp;nbsp; 0 from this function by default. &amp;nbsp;&amp;nbsp; mi = m; &amp;nbsp;&amp;nbsp; if ((mi-&amp;gt;vmajor &amp;lt; 2) || ((mi-&amp;gt;vmajor == 2) &amp;amp;&amp;amp; (mi-&amp;gt;vminor &amp;lt; 20))) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0; &amp;nbsp;&amp;nbsp; //&amp;nbsp; Do your daemon processing here. &amp;nbsp;&amp;nbsp;&amp;nbsp; FILE *fp = fopen(&quot;mercuryDLL.txt&quot;, &quot;a+&quot;); &amp;nbsp;&amp;nbsp;&amp;nbsp; fwrite(&quot;&amp;gt; demon\r\n&quot;, 9, 1, fp ); &amp;nbsp;&amp;nbsp;&amp;nbsp; fclose( fp ); &amp;nbsp;&amp;nbsp; return 0; &amp;nbsp;&amp;nbsp; } //&amp;nbsp; DLLEntryPoint is the standard Win32 DLL entry point for the //&amp;nbsp; module. Usually all we do in this function is store our //&amp;nbsp; Instance handle for use in other places, but any reasonable //&amp;nbsp; initialization processing can be done here as well. BOOL WINAPI DllEntryPoint (HINSTANCE hInst, DWORD reason, LPVOID reserved) &amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp; //WNDCLASS wc; &amp;nbsp;&amp;nbsp; if (reason == DLL_PROCESS_ATTACH) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hLibInstance = hInst; &amp;nbsp;&amp;nbsp; return (TRUE);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Initialization went OK &amp;nbsp;&amp;nbsp; } &amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I also used the template\daemon.h file adding the &lt;/p&gt;&lt;p&gt;#pragma pack(1)&lt;/p&gt;&lt;p&gt; command to the top of that too&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;

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
 

&lt;p&gt;Again, I&#039;ve no idea how your compiler handles this, but maybe you can get some hints from the code to Frans Meijer&#039;s forwarding daemon, which he has made available here:&lt;/p&gt;&lt;p&gt;http://www.xs4all.nl/~fenke/files/&lt;/p&gt;&lt;p&gt;/Rolf &amp;nbsp;&lt;/p&gt;

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 

&lt;p&gt;I tryed compiling that example the other day and still same error message&lt;/p&gt;&lt;p&gt;Like you said it must be how the compilers compiling it.&lt;/p&gt;&lt;p&gt;ive also tryed downloading Borland and compiling it with that but no luck i cant get that to compile at all lol&lt;/p&gt;&lt;p&gt;*my head hurts*&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Thanks for your help anyway, il have a look see and play with it&amp;nbsp;&lt;/p&gt;

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 

&lt;p&gt;Still not managed to get a project to run properly.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Would it be possible for someone to maybe upload a project with some example code&lt;/p&gt;&lt;p&gt;maybe recommend a compiler to use too&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Sorry to be a pain im just trying to implement a half-ass Domain Keys system&lt;/p&gt;&lt;p&gt;basically i want to add a header to out going emails with an OpenSSL checksum&amp;nbsp; of the email.&lt;/p&gt;&lt;p&gt;I dont think theres a way to add a new header with the returned data from a seperate process executed when the emails receieved?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Thanks&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Craig&amp;nbsp;&lt;/p&gt;

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 [;)]

 

 

&lt;p&gt;Hi Craig&lt;/p&gt;&lt;p&gt;Did you finally managed to run your deamon with mercury?&lt;/p&gt;&lt;p&gt; I&#039;ve tried with your example above, to make a little deamon for learning, but without success.&lt;/p&gt;&lt;p&gt;I used too Code::Blocks 8.02 to compiling. Compiling was ok, but It seems that the deamon never was invoked. I&#039;ve tried also VS 2008 but there I couldn&#039;t compile&lt;/p&gt;&lt;p&gt;I&#039;ve you or someone has an good experience please share it with us [;)] &amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;

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 

&lt;p&gt;I&#039;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.&lt;/p&gt;&lt;p&gt;Again, I&#039;m not familiar with the compiler you have been using. Did you check this? (from daemon.txt):&lt;/p&gt;&lt;i&gt;&lt;/i&gt;&lt;blockquote&gt;&lt;i&gt;If you find that your functions do not seem to be getting called by&lt;/i&gt; &lt;i&gt;Mercury, check on the format of the name exported by your compiler - this&lt;/i&gt; &lt;i&gt;is the most likely source of the problem.&lt;/i&gt;&lt;/blockquote&gt;&lt;p&gt;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.&lt;/p&gt;&lt;p&gt;/Rolf&amp;nbsp;&lt;/p&gt;
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft