WindowsService (WinCE).JPG

A simple note from “Write Pure Windows Service” and “How to debug Windows Service”.

Write “Windows Service”

Windows Service is kind of application but it will start when system startup. Windows service will triggerd by “SMC”(System Managed Controller). There is some important note from my writing windows service experience.

  1. **Register your service:
    **What ever your application is big or small. You must register them to SMC before you use it. Please reference ::OpenSCManager() and ::CreateService().
    For more detail please reference Writing a Service Program’s main Function

  2. Start a “Windows Service”.
    You can not startup a windows service via any debugger, you need to startup it on SMC. The SMC will use ::StartServiceCtrlDispatcher to start service and wait for the call back signal “SERVICE_RUNNING”. If you can not startup windows service normally, please let the Service_Status call back and tried to figurate out the root cause. For more detail please refer to Installing a Service

  3. Stop a Windows Service
    When you tried to close a windows service from SMC.The handler will receive a “SERVICE_CONTROL_STOP” from system. Your program have to pass “SERVICE_STOP_PENDING” and call RevokeClassObjects() . For more detail please refer to Stopping a Service.

Debugging “Windows Service”

There are two “easy” ways to debug your Windows service.

  1. Attach Windows service by debugger:
    In VC6 “Build”–> “Start Debug” –>”Attach a process” to point out your service it will use debugger to debug the service.

  2. “Debugging Windows Service”
    use “DebugBreak();”. it will pop up the Window and allow you to debug into Windows Service(You must install VC6 or higher version).

  3. For more detail, please refer this address(How to debug Windows services).

At finally, there is a best practice for you.

2006-03-20:(Update)

Please note:

  1. VC7 or VC8 may have some problem when attach the VC6 debug version. (I think it is the pdb doesn’t match).
  2. To attach the thread. you may need to turn on the “Show system process”, it will show the Windows Service process.

2006-04-12:(Update)

Download Beeper Service Simple Code


Buy Me A Coffee

Evan

Attitude is everything