다음을 통해 공유


Stopping a Running Service (Windows Embedded CE 6.0)

1/6/2010

A service instance may be stopped by a call to the DeregisterService function. DeregisterService identifies and labels the service as invalid. This disallows any call attempts to CreateFile on a given service handle.

DeregisterService takes the same handle value that was returned to the call to RegisterService and not a file handle created using CreateFile. It is possible that an application may not have this handle. For example, if the service was started upon system initialization, the application may not have the handle. In this case, to receive this value, a call to GetServiceHandle must be made. The following code sample shows how to use GetServiceHandle to receive the necessary information.

HANDLE hService = GetServiceHandle(L"TEL0:", NULL, NULL);
if(0 != hService)
     DeregisterService(hService);

Once DeregisterService has been called for the last opened RegisterService,for a particular DLL, the DLL will be unloaded from memory. It is extremely important that no other threads are created by the DLL that is currently running, because unloading the DLL unloads any code pages and this causes all threads running in its context to fail.

See Also

Reference

RegisterService
DeregisterService
GetServiceHandle

Concepts

Services.exe Application Development

Other Resources

Services.exe
CreateFile