Hi Guys I am trying to write a Service application in win32 on XE7 and so far I think I have pulled most of my hair out in frustration. I don't seem to get beyond Starting the Service and as soon as I start it is stopped automatically with a message: "The Unity Express Alerts service on Local Computer started and then stopped. Some services stop automatically if they are not in use buy other services or programs." I looked in the Event Viewer and the log states "Service failed on start: Access violation at address 00A750F4 in module 'AlertService.exe'. Read of address 00000004". Does anyone know how I can debug this ??

Comments

  1. Thanks, but I've already been there! If you read the first line it states: "You can debug service applications by attaching to the service application process when it is already running ". NOTE: already running ! Mine spins up and then dies instantly.

    ReplyDelete
  2. Oh... there is a simple way to debug services just like desktop applications... A little big to post the code here, though. Any way to send you a demo?

    ReplyDelete
  3. Yes, please. my email is antonydanby@gmail.com

    ReplyDelete
  4. Another alternative I sometimes use is to have a special debug build with a loop in the startup code breaking as soon as IsDebuggerPresent returns True. With this you can start the service from the control panel applet and let it break when you attach the debugger to it  from the Delphi IDE.

    ReplyDelete
  5. Back in the good old days, we all knew how to do trace debugging. That skill seems to have been forgotten with the riser of the interactive debugger. 

    Find a programmer over the age of 50 and ask them how to debug it!

    ReplyDelete
  6. Alexandre Machado That works a treat. Didn't think you could stick a debug form into a service; but you live and you learn eh. Thank you very much. I will now debug to my hearts content .... ;-)

    ReplyDelete
  7. David Heffernan I am over 50 ! So what did I miss ;-)

    ReplyDelete
  8. Tony Danby I'm glad ot worked. In fact it is mega simple. I should probably publish this....

    ReplyDelete
  9. Alexandre Machado I couldn't agree with you more. In fact, this way of debugging is better than the way mentioned in Embarcadero's Wiki ( http://docwiki.embarcadero.com/RADStudio/XE7/en/Debugging_Service_Applications ). So, Mr Cantu, if you are reading this ....

    ReplyDelete
  10. Alexandre Machado Indeed you should!  Sounds like it was very useful advice!

    ReplyDelete
  11. David Heffernan Am being a bit thick, sorry; do you mean DebugView and OutputDebugString? Can that be used inside a TService as it cranks up?

    ReplyDelete
  12. Tony Danby It can. I use it all the time.

    ReplyDelete
  13. Thanks to everyone for all the assistance today. I have managed to get quite along way. 

    I have a bit of a weird one though. When I run my service in debug mode and step through it ( using Alexandre's debug form to Start/Stop the Service ) everything is fine, but when I make a release build and install it, then try to Start it. I get:

    Service failed on start: List index out of bounds (0)
    ( from the Event viewer ).

    I have used OutputDebugString to try and hunt it down. When I install it, It get's through my DPR debug fine. It gets through my ServiceAfterInstall() and all the debug comes out positive. I have debug in my ServiceStart() right at the VERY TOP and when I click Start, I get the error mentioned and NOTHING in the debug.

    Very very weird. Has anyone got any ideas ??

    ReplyDelete
  14. OutputDebugString is indeed one way to do trace debugging. Certainly for debugging service startup issues then that form of debugging can be the most effective.

    ReplyDelete
  15. To add to the weirdness of my last comment; none of my own debug comes out, but I do get ( if I wait for about 10 seconds or so ):

    [944] RenderEventToBuffer failed because of insufficient memory.-122-The data area passed to a system call is too small 
    [944] RenderEventToBuffer failed because of insufficient memory.-122-The data area passed to a system call is too small 
    [944] Trace Start:0End Index:6 
    [944] Unable to get Publisher metadata for AlertSvc-2-The system cannot find the file specified 
    [944] Trace Start:0End Index:6 

    My app/service is called AlertSvc, so I am guessing it is debug for my Service and not something else somewhere on my PC. Not only that, I have attempted to start my service about half a dozen or so times and this debug always comes back after a short wait.

    If anyone can help I would be grateful.

    Thanks

    ReplyDelete

Post a Comment