Monday, December 12, 2005

/* Rambling comments... */: Testing Windows Services

Len always have some cool idea on how to program effectively. The atl framework my service based on has some good design to debug the OnStart method. In the debug mode, it will be registed as "Local Service", this will make it easier to run it in debug mode.

However, the only way I can stop the servcie is press "shift-F5" , and this cannot help me much in debugging the right clean code.

Inside RunMessageLoop, my service is waiting for the ShutdownEvent , if running as a service, that event will be sent throgh the SCM (The SCM registered the handler function like this:

void Handler(DWORD dwOpcode) throw()
{
T* pT = static_cast(this);

switch (dwOpcode)
{
case SERVICE_CONTROL_STOP:
pT->OnStop();
break;
case SERVICE_CONTROL_PAUSE:
pT->OnPause();
break;
case SERVICE_CONTROL_CONTINUE:
pT->OnContinue();
break;
case SERVICE_CONTROL_INTERROGATE:
pT->OnInterrogate();
break;
case SERVICE_CONTROL_SHUTDOWN:
pT->OnShutdown();
break;
default:
pT->OnUnknownRequest(dwOpcode);
}
}

But in debugging mode, the event can be simulated from a different process. This will rely on a named event, which can communicate between different processes.

No comments: