Windows Perl Scripting Forums » News

Updated: Win32::Daemon v20080324 beta

(15 posts)


  1. Dave
    Perl guy

    After quite some time I have updated the Win32::Daemon. The big change is that the main code now is in XS format. If you don't know what that is then just don't worry about it.

    I have fixed bugs and made some slight changes per tons of requests.

    You can give it a try by manually installing it:

    It has been compiled for ActiveState Perl v5.6, 5.8 and 5.10. An x64 version is forthcoming.

    This "beta" release contains:
    <font size="2">

    - Converted to XS file.

    - Fixed callback heartbeat: now properly calls back with SERVICE_RUNNING (not SERVICE_CONTROL_RUNNING)

    - StopService() will post WM_QUIT message to the ServiceMain() thread to shut down the service thread.

    - Calling into StopService() will auto change the state to STOPPING/STOPPED so you do not need to

    explicitly do so (calling State() or a callback returning STOPPING/STOPPED).

    20070102 rothd

    - Cleaned up a bit.

    - Added WM_QUIT message to the ServiceMain function. Now the Perl StopService() will

    post this message to shut down the service thread.

    - Fixed bug where messages were posted to wrong thread.

    20080321 rothd

    - Added support for SERVICE_CONTROL_PRESHUTDOWN.

    - Callbacks can now return a state value. This is the functional equivilent of calling

    Win32::Daemon::State( $NewState ) before returning:

    // sub EventCallback

    // {

    // my( $Event, $Context ) = @_;

    // # Process the event

    // Win32::Daemon::State( $NewState );

    // return;

    // }

    // =================== SAME AS ====================

    // sub EventCallback

    // {

    // my( $Event, $Context ) = @_;

    // # Process the event

    // return( $NewState );

    // }


    - Callback timer works correctly!

    - CALLBACK_RUNNING has been depreciated and replaced with CALLBACK_TIMER. It is only called

    when the timer (set by CallbackTimer()) has expired. Use this as a heartbeat. You only need

    to set it once either with CallbackTimer() or passing in the timer value when calling into


    Set the callback using "timer" as the callback name. Using "running" will also work but it

    is mapped to "timer". If you specify both, only "timer" will be registered.

    - Created to help with testing services.

    - Pruned out unnecessary stuff from file.




    Posted 11 years ago #
  2. murat

    Hi Dave,

    Thanks for developing Win32::Daemon.

    I've downloaded v20080324 beta of Win32::Daemon for 5.10 and started to test on Windows XP SP2. My perl version is "v5.10.0 built for MSWin32-x86-multi-thread".

    Before trying to run my script and trying to adapt it to the latest version of Win32::Daemon (if any change required), I tried the test scripts comes with your binary distribution.

    First of all, I ran to install test service which resulted in success, then I run from the cmd console. After StartService call, "CallbackRoutine" is called each 2 seconds as expected. However, state is always unknown (4128). Here is the log snippet:


    # Service Starting
    # Script:
    # Perl:
    # PID: 368
    # Date: Tue Apr  1 11:51:27 2008
    [Tue Apr  1 11:51:27 2008] Starting service
    [Tue Apr  1 11:51:29 2008] Got an unknown state: 4128
    [Tue Apr  1 11:51:31 2008] Got an unknown state: 4128
    [Tue Apr  1 11:51:33 2008] Got an unknown state: 4128
    [Tue Apr  1 11:51:35 2008] Got an unknown state: 4128
    [Tue Apr  1 11:51:37 2008] Got an unknown state: 4128
    [Tue Apr  1 11:51:39 2008] Got an unknown state: 4128
    [Tue Apr  1 11:51:41 2008] Got an unknown state: 4128

    Do you have any comment about this situation ? I've looked at winsvc.h, but I couldn't find what the state value 4128 (0x1020) means. Could it be a bug or due to something like misconfiguration ?

    Starting the service from service manager console also failed. Here is the related log snippet:

    # Service Starting
    # Script: C:\test\
    # Perl:
    # PID: 3116
    # Date: Tue Apr  1 13:01:33 2008
    [Tue Apr  1 13:01:33 2008] Starting service
    [Tue Apr  1 13:01:33 2008] Got an unknown state: 4112
    [Tue Apr  1 13:01:35 2008] Got an unknown state: 4128
    [Tue Apr  1 13:01:37 2008] Got an unknown state: 4128
    [Tue Apr  1 13:01:39 2008] Got an unknown state: 4128
    [Tue Apr  1 13:01:41 2008] Got an unknown state: 4128
    [Tue Apr  1 13:01:43 2008] Got an unknown state: 4128

    As you can see, for the first enterance to CallbackRoutine, we got state 4112 (0x1010), an then 4128 (0x1020) until the script terminates.

    Similar things happen when i run




    Posted 11 years ago #
  3. Dave
    Perl guy

    For this release we had to fix up some bugs including constant value collisions. To do this we are emphasizing the differences between "states" and "control messages". States represent the actual state of the service such as SERVICE_START_PENDING and SERVICE_PAUSED. Control messges represent something which has happened that the Service Control Manager is telling us about such as SERVICE_CONTROL_SHUTDOWN or SERVICE_CONTROL_TIMER.

    Callbacks occur because of a control message. That is what is passed into the callback routine. So if the user pauses the service the callback will pass in SERVICE_CONTROL_PAUSE. The state you can find from Win32::Daemon::State() will be SERVICE_PAUSE_PENDING. THe callback needs to change the state to SERVICE_PAUSED.

    So what you are seeing are the control messages passed into the callback. The message 4112 (0x1010) is SERVICE_CONTROL_START and the message 4128 (0x1020) is SERVICE_CONTROL_TIMER (the callback timer). I'll have to update the test scripts to better demonstrate this.


    Posted 11 years ago #
  4. murat


    Since SERVICE_CONTROL_START and SERVICE_CONTROL_TIMER are undefined i had to do a fix (until the new version of Win32::Daemon released) and define them manually as follows:

            use constant SERVICE_CONTROL_START => 0x1010; # 4112
            use constant SERVICE_CONTROL_TIMER => 0x1020; # 4128

    Then, in my CallbackRoutine i'm able to use those constants...


        if( SERVICE_CONTROL_START == $State )
                $service->_start( );
                $Context->{last_state} = SERVICE_RUNNING;
        elsif( SERVICE_CONTROL_TIMER == $State )



    And now my service runs properly... 

    Thanks a lot... 

    Posted 11 years ago #
  5. Anonymous

    >You can give it a try by manually installing it:

    How to manually install it?

    ppm install win32-Daemon.ppd 

    does not work (( 

    Posted 10 years ago #
  6. Anonymous

    NOTICE: In documentation there is nothing about SERVICE_CONTROL_TIMER

    Update please DOCs 

    Posted 10 years ago #
  7. Lennon

    i can't install daemon 

     activeperl 5.10

    ppm.bat install
    ppm.bat install failed: The PPD does not provide code to install for this platform

    ppm.bat install win32-daemon.ppd
    Downloading Win32-Daemon-0.2008.03.24...not found
    ppm install failed: 404 Not Found

    Posted 10 years ago #
  8. Lennon

    it doesn't work with 5.10, install 5.8

    Posted 10 years ago #
  9. Anonymous

    How to manually install:

    create  C:\Perl\site\lib\Win32\Daemon

    copy  test/* to C:\Perl\site\lib\Win32\Daemon

    copy daemon.htm history.txt Win32-daemon.ppd to  C:\Perl\site\lib\Win32\Daemon

    create  C:\Perl\site\lib\auto\Win32\Daemon\

    copy bin/* to  C:\Perl\site\lib\auto\Win32\Daemon\

    And you get working Win32::Daemon  for 5.10

    if you are using Win32::Daemon::RegisterCallbacks use   'timer'  for  \&Callback_Running, running does not work!

    Also nitice: callback_running are called before callback_start is finished!

    in Callback_running instead of  "if( SERVICE_RUNNING == Win32::Daemon::State() ) {"
    use   "if( $event == 4128 ) {"

    Posted 10 years ago #
  10. peter65

    Is QueryLastMessage not working in current version?

    Posted 10 years ago #
  11. bdscott

    Can't find which I presume is a shortened version of QueryLastMessage. I'm guessing this is the same/or similar to peter65's post.

    Installed in a similar way to KES's suggestion:
    md c:\Perl\html\site\lib\Win32
    copy daemon.htm c:\Perl\html\site\lib\Win32\
    md c:\Perl\site\lib\Win32
    copy c:\Perl\site\lib\Win32\
    md c:\Perl\site\lib\auto\Win32\Daemon
    copy bin\daemon.dll c:\Perl\site\lib\auto\Win32\Daemon\

    Posted 10 years ago #
  12. Anonymous

    see sources, maybe it was changed also as running by timer

    Posted 10 years ago #
  13. Anonymous

    Quote from KES

    How to manually install:

    create C:\Perl\site\lib\Win32\Daemon

    copy test/* to C:\Perl\site\lib\Win32\Daemon

    copy daemon.htm history.txt Win32-daemon.ppd to C:\Perl\site\lib\Win32\Daemon

    create C:\Perl\site\lib\auto\Win32\Daemon\

    copy bin/* to C:\Perl\site\lib\auto\Win32\Daemon\

    And you get working Win32::Daemon for 5.10

    End Quote

    There was only one step missing from this, and it took me forever to find, you need to also copy over DAEMON.PM from the daemon_5.10 folder to C:\Perl\site\lib\Win32 folder

    Without this step, it doesn't recognize that Daemon is installed, at least not on my windows box. Hope this helps some other people

    Posted 9 years ago #
  14. peter65

    Hi Dave,
    you have forgotten to publish your bugfixes to Win32::Daemon since one and a half year! Please do it now.

    Posted 9 years ago #
  15. Anonymous


    I'm using perl 5.10 and have manually installed Win32:Daemon, however, when I run my perl program I'm getting the same error that some other people previously reported:

    Can't locate auto/Win32/Daemon/ in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at line 547

    Is there any way that I can fix this problem myself? Any help would be greatly appreciated!

    Thanks, DG

    Posted 9 years ago #

RSS feed for this topic


You must log in to post.