Skip to content

Latest commit

 

History

History
165 lines (120 loc) · 6.49 KB

nf-winsvc-registerservicectrlhandlerexw.md

File metadata and controls

165 lines (120 loc) · 6.49 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:winsvc.RegisterServiceCtrlHandlerExW
RegisterServiceCtrlHandlerExW function (winsvc.h)
Registers a function to handle extended service control requests. (Unicode)
RegisterServiceCtrlHandlerEx
RegisterServiceCtrlHandlerEx function
RegisterServiceCtrlHandlerExW
_win32_registerservicectrlhandlerex
base.registerservicectrlhandlerex
winsvc/RegisterServiceCtrlHandlerEx
winsvc/RegisterServiceCtrlHandlerExW
base\registerservicectrlhandlerex.htm
security
23eea346-9899-4214-88f4-9b7eb7ce1332
12/05/2018
RegisterServiceCtrlHandlerEx, RegisterServiceCtrlHandlerEx function, RegisterServiceCtrlHandlerExA, RegisterServiceCtrlHandlerExW, _win32_registerservicectrlhandlerex, base.registerservicectrlhandlerex, winsvc/RegisterServiceCtrlHandlerEx, winsvc/RegisterServiceCtrlHandlerExA, winsvc/RegisterServiceCtrlHandlerExW
winsvc.h
Windows.h
Windows
Windows XP [desktop apps only]
Windows Server 2003 [desktop apps only]
RegisterServiceCtrlHandlerExW (Unicode) and RegisterServiceCtrlHandlerExA (ANSI)
Advapi32.lib
Advapi32.dll
Windows
19H1
RegisterServiceCtrlHandlerExW
winsvc/RegisterServiceCtrlHandlerExW
c++
APIRef
kbSyntax
DllExport
Advapi32.dll
API-MS-Win-DownLevel-AdvApi32-l2-1-1.dll
sechost.dll
API-MS-Win-Service-Core-l1-1-0.dll
API-MS-Win-Service-Core-l1-1-1.dll
API-MS-Win-Service-Winsvc-l1-1-0.dll
API-MS-Win-Service-Winsvc-l1-2-0.dll
API-Ms-Win-Service-Core-L1-1-2.dll
RegisterServiceCtrlHandlerEx
RegisterServiceCtrlHandlerExA
RegisterServiceCtrlHandlerExW

RegisterServiceCtrlHandlerExW function

-description

Registers a function to handle extended service control requests.

-parameters

-param lpServiceName [in]

The name of the service run by the calling thread. This is the service name that the service control program specified in the CreateService function when creating the service.

-param lpHandlerProc [in]

A pointer to the handler function to be registered. For more information, see HandlerEx.

-param lpContext [in, optional]

Any user-defined data. This parameter, which is passed to the handler function, can help identify the service when multiple services share a process.

-returns

If the function succeeds, the return value is a service status handle.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

The following error codes can be set by the service control manager.

Return code Description
ERROR_NOT_ENOUGH_MEMORY
Not enough memory is available to convert an ANSI string parameter to Unicode. This error does not occur for Unicode string parameters.
ERROR_SERVICE_NOT_IN_EXE
The service entry was specified incorrectly when the process called the StartServiceCtrlDispatcher function.

-remarks

The ServiceMain function of a new service should immediately call the RegisterServiceCtrlHandlerEx function to register a control handler function with the control dispatcher. This enables the control dispatcher to invoke the specified function when it receives control requests for this service. For a list of possible control codes, see HandlerEx. The threads of the calling process can use the service status handle returned by this function to identify the service in subsequent calls to the SetServiceStatus function.

The RegisterServiceCtrlHandlerEx function must be called before the first SetServiceStatus call because RegisterServiceCtrlHandlerEx returns a service status handle for the caller to use so that no other service can inadvertently set this service status. In addition, the control handler must be in place to receive control requests by the time the service specifies the controls it accepts through the SetServiceStatus function.

When the control handler function is invoked with a control request, the service must call SetServiceStatus to report status to the service control manager only if the service status has changed, such as when the service is processing stop or shutdown controls. If the service status has not changed, the service should not report status to the service control manager.

The service status handle does not have to be closed.

Note

The winsvc.h header defines RegisterServiceCtrlHandlerEx as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

-see-also

CreateService

HandlerEx

Service Control Handler Function

Service Functions

ServiceMain

SetServiceStatus