How to debug a service code?
-
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
-
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
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 )