Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. System Admin
  4. How to debug a service code?

How to debug a service code?

Scheduled Pinned Locked Moved System Admin
debugginghelptutorialquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi all, I wrote a service for w2k. But there are something wrong in the ServiceMain() function. because I can not start this service but when i simplize ServiceMain() It works ok. ( I start another thread in the ServiceMain() and call DeviceIoControl() in it). I want to debug the ServiceMain(). But don't know how to do it. I only know how to start and debug the Service control code in another project. Thanks for help. I am very anxious

    D 1 Reply Last reply
    0
    • A Anonymous

      Hi all, I wrote a service for w2k. But there are something wrong in the ServiceMain() function. because I can not start this service but when i simplize ServiceMain() It works ok. ( I start another thread in the ServiceMain() and call DeviceIoControl() in it). I want to debug the ServiceMain(). But don't know how to do it. I only know how to start and debug the Service control code in another project. Thanks for help. I am very anxious

      D Offline
      D Offline
      Daniel Lohmann
      wrote on last edited by
      #2

      This is a programming question and should better reside in the Visual C++ forum. :| Having said that, here is the solution:

      #define HARDBREAK __asm int 3

      void WINAPI ServiceMain( DWORD dwArgc, LPTSTR* apszArgs )
      {
      ...
      HARDBREAK;
      ...
      }

      The above HARDBREAK macro inserts a hard-coded breakpoint into your code. (Software interrupt 3 is used for breakpoints on x86). If you run your service (via SCM) and control reaches this possition a "Unhandled exception" message box of windows will appear. Choose cancle to debug your app and - voila you will find yourself in the debugger with the app halted as exactly this position. From there you could single-step, insert watches, etc. Please post any F-ups to this to the Visual C++ Forum :cool: -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups