Unloading a Service (Windows Embedded CE 6.0)
1/6/2010
A service instance may be stopped by a call to the DeregisterService function.
The following code sample shows how to unload a service. Running this code sample will cause the service DLL to be unloaded completely from the service host, unless the service is marked with the DEVFLAGS_NOUNLOAD flag. If this flag is set, any attempt to unload the service will fail. You must call ActivateServiceto reload an unloaded service.
In this code sample, szServicePrefix will be a service prefix, for example in the form “HTP0:”.
HANDLE h = CreateFile(szServicePrefix,GENERIC_READ|GENERIC_WRITE,0,
NULL,OPEN_EXISTING,0,NULL);
if (h == INVALID_HANDLE_VALUE) {
return 0;
}
DEVMGR_DEVICE_INFORMATION devInfo;
devInfo.dwSize = sizeof(devInfo);
if (! GetDeviceInformationByFileHandle(h,&devInfo)) {
CloseHandle(h);
return 0;
}
// Must close handle before unloading so there's no open references.
CloseHandle(h);
if (! DeregisterService(devInfo.hDevice)) {
return 0;
}
See Also
Reference
RegisterService
DeregisterService
ActivateService
Concepts
Services.exe Application Development