If a service takes too long to start the service control manager kills the service.
The way to stop this is for a service to call ReportStatusToSCMgr() to tell the service control manager that the service is still OK.
Memory Validator can't do this for you as the call requires some data from any earlier call you have made.
The solution is that you provide a callback using svlMVStub_SetServiceCallback() that Memory Validator can call during the process of attaching to the service, and you can call the appropriate function.
Example code to set the callback:
errCode = svlMVStub_SetServiceCallback(serviceCallback, // the callback
NULL); // some user data (we don't have any, so set NULL)
if (bLogging)
{
if (errCode != SVL_OK)
{
svlMVStub_writeToLogFileW(L"Setting service callback failed. \r\n");
svlMVStub_writeToLogFile(errCode);
}
svlMVStub_writeToLogFileW(L"Starting Memory Validator\r\n");
}
Example callback:
static void serviceCallback(void *userParam)
{
// just tell the Service Control Manager that we are still busy
// in this example userParam is not used
//
// note that prior to the Validator loading it's DLL ssStatus.dwCurrentState must have been initialised, most likely to SERVICE_START_PENDING
// you could pass a fixed value here, but it would need to change once the service has finished starting up so that you don't unintentionally change the service state
// when this callback is called. This callback is called whenever instrumentation happens (when a DLL is loaded). Thus you can't assume this is only called during service startup,
// it may also get called later in the service lifetime.
ReportStatusToSCMgr(ssStatus.dwCurrentState, // service state
NO_ERROR, // exit code
3000); // wait hint
}
We strongly recommend that you set a service callback. It won't harm your program and it will remove any likelihood of your service being killed by the service control manager.
If you have problems getting Memory Validator to monitor your service you'll need to find out what's failing.
Until Memory Validator loads correctly and successfully connects to the graphical user interface you have no way of knowing what is happening.
The solution is to set a log file that Memory Validator can write status messages to. You can also write your own status messages to this log file.
Set the log file using svlMVStub_setLogFileName. Write to it using svlMVStub_writeToLogFile(), svlMVStub_writeToLogFileA(), svlMVStub_writeToLogFileW().
Then when things are not working as expected take a look at the log file to see the errors. The Memory Validator will often suggest what the problem is.
We strongly recommend that you configure the log file and use it when working with services. It has saved us a lot of time.