You did not show us the worker thread creation and function and the
MyServiceSet
and
MyServiceHandler
implementations. So we can't locate problems within those function.
MyServiceSet(SERVICE_RUNNING);
MyServiceSet(SERVICE_STOPPED);
A service usually creates a thread there instead:
MyServiceSet(SERVICE_RUNNING);
HANDLE hThread = CreateThread (NULL, 0, ServiceWorkerThread, NULL, 0, NULL);
WaitForSingleObject(hThread, INFINITE);
MyServiceSet(SERVICE_STOPPED);
DWORD WINAPI ServiceWorkerThread(LPVOID lpParam)
{
while (WaitForSingleObject(g_ExitEvent, SOME_TIMEOUT) != WAIT_OBJECT_0)
{
}
return 0;
}
g_ExitEvent
has to be set by the
MyServiceHandler
upon
SERVICE_CONTROL_STOP
.
Finally, just to be sure: Have you installed your service?