网站首页  词典首页

请输入您要查询的函数:

 

术语 handlerex
释义 HandlerEx
语法:
C++
DWORD WINAPI HandlerEx(
__in DWORD dwControl,
__in DWORD dwEventType,
__in LPVOID lpEventData,
__in LPVOID lpContext
);
HandlerEx回调函数
一个应用程序定义的回调函数与RegisterServiceCtrlHandlerEx功能使用。一个服务程序可以使用特定服务控制处理程序函数。
在LPHANDLER_FUNCTION_EX类型定义一个指向此功能。 HandlerEx是一个应用程序的占位符定义的名称。
这个函数取代处理程序控制处理功能与RegisterServiceCtrlHandler函数使用。一个服务可以使用控制处理程序,但新的控制处理程序支持用户定义的上下文数据的和额外的扩展的控制代码。
参数
dwControl [in]
控制代码。此参数可以是下列值之一。
控制codeMeaning
SERVICE_CONTROL_CONTINUE
0x00000003Notifies已暂停服务,它应该恢复。
SERVICE_CONTROL_INTERROGATE
0x00000004Notifies服务报告其当前的状态信息服务控制管理器。
处理程序应该简单地返回NO_ERROR,在供应链管理是对服务的当前状态认识。
SERVICE_CONTROL_NETBINDADD
0x00000007Notifies的网络服务是有约束力的新的组成部分。该服务应绑定到新的组件。
应用程序应该使用即插即用功能代替。
SERVICE_CONTROL_NETBINDDISABLE
0x0000000ANotifies网络服务,其绑定一个已被禁用。该服务应重读其绑定信息和删除具有约束力。
应用程序应该使用即插即用功能代替。
SERVICE_CONTROL_NETBINDENABLE
0x00000009Notifies网络服务,弱能约束力已被启用。该服务应重读其绑定信息和添加新的具有约束力。
应用程序应该使用即插即用功能代替。
SERVICE_CONTROL_NETBINDREMOVE
0x00000008Notifies的网络服务,一个有约束力的组成部分已被删除。重读的服务应该从消除组件的绑定信息和unbind。
应用程序应该使用即插即用功能代替。
SERVICE_CONTROL_PARAMCHANGE
0x00000006Notifies a service that service-specific startup parameters have changed.该服务应重读其启动参数。
SERVICE_CONTROL_PAUSE
0x00000002Notifies一种服务,它应该暂停。
SERVICE_CONTROL_PRESHUTDOWN
0x0000000FNotifies一种服务,该系统将关闭。服务需要更多的时间来履行超出在系统关机时间紧迫限制清除任务可以使用此通知。服务控制管理器发送此通知已登记之前,它发送SERVICE_CONTROL_SHUTDOWN通知对已经注册的该通知的申请。
阿服务,处理此通知阻止系统关闭,直到服务停止或preshutdown的时间间隔内通过SERVICE_PRESHUTDOWN_INFO指定-届满。由于这会影响用户体验,服务应使用此功能仅当它是绝对必要的,以避免在下次系统启动时的数据丢失或明显的恢复时间。
Windows Server 2003和Windows XP/2000操作系统:此值不支持。
SERVICE_CONTROL_SHUTDOWN
0x00000005Notifies的服务,该系统正在关闭这样的服务可以执行清除任务。请注意,服务为SERVICE_CONTROL_PRESHUTDOWN通知,登记册无法收到此通知,因为他们已经停止。
如果服务接受这一控制代码,它必须停止执行后,其清理任务并返回NO_ERROR。单片机发送后,这个控制代码,它将不会发出其他控制代码的服务。
有关更多信息,请参阅本主题的备注部分。
SERVICE_CONTROL_STOP
0x00000001Notifies一种服务,它应该停止。
如果服务接受这一控制代码,它必须停止在收到并返回NO_ERROR。单片机发送后,这个控制代码,它将不会发出其他控制代码的服务。
Windows XP/2000操作系统:如果服务返回NO_ERROR并继续运行,它继续得到控制代码。开始更改此行为与Windows Server 2003和Windows XP SP2的。
此参数也可以是以下扩展控制代码之一。请注意,这些控制代码不被处理程序功能的支持。
控制CodeMeaning
SERVICE_CONTROL_DEVICEEVENT
0x0000000BNotifies的设备事件的服务。 (该服务必须已登记在收到这些通知使用RegisterDeviceNotification功能。)
SERVICE_CONTROL_HARDWAREPROFILECHANGE
0x0000000CNotifies 1计算机的硬件配置已更改服务。
SERVICE_CONTROL_POWEREVENT
0x0000000DNotifies的系统电源事件的服务。
SERVICE_CONTROL_SESSIONCHANGE
0x0000000ENotifies某届更改事件的服务。请注意,服务只对用户登录通知如果它完全在登录尝试加载的进展。
Windows 2000中:此值不支持。
SERVICE_CONTROL_TIMECHANGE
0x00000010Notifies一个系统时间已更改服务。
Windows Server 2008中,Windows Vista中的Windows Server 2003,和Windows XP/2000:此控制代码不支持。
SERVICE_CONTROL_TRIGGEREVENT
0x00000020Notifies为服务触发事件,事件发生的注册服务。
Windows Server 2008中,Windows Vista中的Windows Server 2003,和Windows XP/2000:此控制代码不支持。
此参数也可以是一个用户定义的控制代码,如下表所述。
控制codeMeaning
范围128 255.The服务定义与控制代码相关联的行动。
dwEventType [in]
事件的类型已经发生。使用此参数,如果dwControl是SERVICE_CONTROL_DEVICEEVENT,SERVICE_CONTROL_HARDWAREPROFILECHANGE,SERVICE_CONTROL_POWEREVENT,或SERVICE_CONTROL_SESSIONCHANGE。否则,它是零。
如果dwControl是SERVICE_CONTROL_DEVICEEVENT,这个参数可以是下列值之一:
DBT_DEVICEARRIVAL
DBT_DEVICEREMOVECOMPLETE
DBT_DEVICEQUERYREMOVE
DBT_DEVICEQUERYREMOVEFAILED
DBT_DEVICEREMOVEPENDING
DBT_CUSTOMEVENT
如果dwControl是SERVICE_CONTROL_HARDWAREPROFILECHANGE,这个参数可以是下列值之一:
DBT_CONFIGCHANGED
DBT_QUERYCHANGECONFIG
DBT_CONFIGCHANGECANCELED
如果dwControl是SERVICE_CONTROL_POWEREVENT,这个参数可以是在WM_POWERBROADCAST消息wParam参数指定的值之一。
如果dwControl是SERVICE_CONTROL_SESSIONCHANGE,这个参数可以是在WM_WTSSESSION_CHANGE消息wParam参数指定的值之一。
lpEventData [in]
其他设备的信息,如果需要。这些数据的格式取决于该dwControl和dwEventType参数值。如果dwControl是SERVICE_CONTROL_DEVICEEVENT,这些数据对应于lParam参数,应用程序作为一个接收WM_DEVICECHANGE消息的一部分。如果dwControl是SERVICE_CONTROL_POWEREVENT和dwEventType是PBT_POWERSETTINGCHANGE,这个数据是一个POWERBROADCAST_SETTING结构的指针。如果dwControl是SERVICE_CONTROL_SESSIONCHANGE,这个参数是一个指向WTSSESSION_NOTIFICATION结构的指针。
lpContext [in]
用户从RegisterServiceCtrlHandlerEx通过定义的数据。当多个服务共享一个进程,lpContext参数可以帮助识别服务。
返回值
该函数的返回值的控制代码依赖欢迎。
下面的列表标识这个返回值的规则:
一般来说,如果您的服务不处理控制,返回ERROR_CALL_NOT_IMPLEMENTED。不过,您的服务,应返回以下事件,即使您的服务不处理他们:SERVICE_CONTROL_INTERROGATE NO_ERROR。
如果您的服务处理SERVICE_CONTROL_DEVICEEVENT,返回NO_ERROR准予要求和错误代码拒绝该请求。
如果您的服务处理SERVICE_CONTROL_HARDWAREPROFILECHANGE,返回NO_ERROR准予要求和错误代码拒绝该请求。
如果您的服务处理SERVICE_CONTROL_POWEREVENT,返回NO_ERROR准予要求和错误代码拒绝该请求。
对于所有其他控制代码的服务处理,返回NO_ERROR。
备注
当服务启动时,它的ServiceMain函数应立即调用RegisterServiceCtrlHandlerEx函数指定HandlerEx函数来处理控制请求。若要指定控制代码被接受,使用SetServiceStatus和RegisterDeviceNotification功能。
在以服务为主线的控制调度调用指定服务的控制处理功能只要它接收从服务控制管理器控制的要求。处理后的控制要求,控制处理程序必须调用SetServiceStatus如果服务状态改变报告其新的地位的服务控制管理器。
控制处理功能主要是为了接收通知,并立即返回。因此,最好是回调函数保存其参数,并创建其他线程执行其他工作。您的应用程序必须确保这些线程停止服务前退出。
当服务控制管理器控制代码发送到服务,它等待返回发送之前额外控制代码的其他服务处理函数。控制处理程序必须在30秒内返回的供应链管理或返回一个错误。如果服务必须做冗长的处理时,服务控制处理程序执行,应建立一个辅助线程来执行长时间的加工,然后返回的控制处理。这可以防止绑管制的调度和阻止接收控制码的其他服务的服务。
控制代码的SERVICE_CONTROL_SHUTDOWN只应处理的服务,必须绝对干净,在关机时,因为有一个有限的时间(约20秒)可用于服务关闭。过了这段时间到期时,系统关闭的收益,不论是完整的服务关闭。请注意,如果系统在关机的状态(不重新启动或关机),服务继续运行。
如果服务需要更多的时间来清理,它应STOP_PENDING状态消息,伴随着等待提示,因此,服务控制器知道要等待多久报告之前的系统的服务关闭就完成了。然而,为了防止关机停止服务,有多久服务控制器限制等待。如果该服务被关闭了通过服务管理单元中,限额为125秒。如果操作系统是重新启动,在指定的时限在以下注册表项WaitToKillServiceTimeout的值:
HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\控制
一定要处理即插即用尽快播放设备事件,否则,系统可能会变得没有反应。如果您的事件处理程序执行的操作可能会阻止执行(如I / O)的,最好是启动另一个线程来执行该操作异步。
服务还可以使用SetConsoleCtrlHandler函数以接收关闭通知。收到此通知时,正在运行的应用程序关闭,它发生服务之前关闭。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinSvc.h(头文件:winuser.h)
参见
RegisterDeviceNotification
RegisterServiceCtrlHandlerEx
服务控制处理函数
服务函数
ServiceMain
SetServiceStatus
WM_DEVICECHANGE
WM_POWERBROADCAST
WM_WTSSESSION_CHANGE
POWERBROADCAST_SETTING
WTSSESSION_NOTIFICATION
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==HandlerEx Callback Function
An application-defined callback function used with the RegisterServiceCtrlHandlerEx function. A service program can use it as the control handler function of a particular service.
The LPHANDLER_FUNCTION_EX type defines a pointer to this function. HandlerEx is a placeholder for the application-defined name.
This function supersedes the Handler control handler function used with the RegisterServiceCtrlHandler function. A service can use either control handler, but the new control handler supports user-defined context data and additional extended control codes.
Syntax
C++
DWORD WINAPI HandlerEx(
__in DWORD dwControl,
__in DWORD dwEventType,
__in LPVOID lpEventData,
__in LPVOID lpContext
);
Parameters
dwControl [in]
The control code. This parameter can be one of the following values.
Control codeMeaning
SERVICE_CONTROL_CONTINUE
0x00000003Notifies a paused service that it should resume.
SERVICE_CONTROL_INTERROGATE
0x00000004Notifies a service to report its current status information to the service control manager.
The handler should simply return NO_ERROR; the SCM is aware of the current state of the service.
SERVICE_CONTROL_NETBINDADD
0x00000007Notifies a network service that there is a new component for binding. The service should bind to the new component.
Applications should use Plug and Play functionality instead.
SERVICE_CONTROL_NETBINDDISABLE
0x0000000ANotifies a network service that one of its bindings has been disabled. The service should reread its binding information and remove the binding.
Applications should use Plug and Play functionality instead.
SERVICE_CONTROL_NETBINDENABLE
0x00000009Notifies a network service that a disabled binding has been enabled. The service should reread its binding information and add the new binding.
Applications should use Plug and Play functionality instead.
SERVICE_CONTROL_NETBINDREMOVE
0x00000008Notifies a network service that a component for binding has been removed. The service should reread its binding information and unbind from the removed component.
Applications should use Plug and Play functionality instead.
SERVICE_CONTROL_PARAMCHANGE
0x00000006Notifies a service that service-specific startup parameters have changed. The service should reread its startup parameters.
SERVICE_CONTROL_PAUSE
0x00000002Notifies a service that it should pause.
SERVICE_CONTROL_PRESHUTDOWN
0x0000000FNotifies a service that the system will be shutting down. Services that need additional time to perform cleanup tasks beyond the tight time restriction at system shutdown can use this notification. The service control manager sends this notification to applications that have registered for it before sending a SERVICE_CONTROL_SHUTDOWN notification to applications that have registered for that notification.
A service that handles this notification blocks system shutdown until the service stops or the preshutdown time-out interval specified through SERVICE_PRESHUTDOWN_INFO expires. Because this affects the user experience, services should use this feature only if it is absolutely necessary to avoid data loss or significant recovery time at the next system start.
Windows Server 2003 and Windows XP/2000: This value is not supported.
SERVICE_CONTROL_SHUTDOWN
0x00000005Notifies a service that the system is shutting down so the service can perform cleanup tasks. Note that services that register for SERVICE_CONTROL_PRESHUTDOWN notifications cannot receive this notification because they have already stopped.
If a service accepts this control code, it must stop after it performs its cleanup tasks and return NO_ERROR. After the SCM sends this control code, it will not send other control codes to the service.
For more information, see the Remarks section of this topic.
SERVICE_CONTROL_STOP
0x00000001Notifies a service that it should stop.
If a service accepts this control code, it must stop upon receipt and return NO_ERROR. After the SCM sends this control code, it will not send other control codes to the service.
Windows XP/2000: If the service returns NO_ERROR and continues to run, it continues to receive control codes. This behavior changed starting with Windows Server 2003 and Windows XP with SP2.

This parameter can also be one of the following extended control codes. Note that these control codes are not supported by the Handler function.
Control CodeMeaning
SERVICE_CONTROL_DEVICEEVENT
0x0000000BNotifies a service of device events. (The service must have registered to receive these notifications using the RegisterDeviceNotification function.)
SERVICE_CONTROL_HARDWAREPROFILECHANGE
0x0000000CNotifies a service that the computer's hardware profile has changed.
SERVICE_CONTROL_POWEREVENT
0x0000000DNotifies a service of system power events.
SERVICE_CONTROL_SESSIONCHANGE
0x0000000ENotifies a service of session change events. Note that a service will only be notified of a user logon if it is fully loaded before the logon attempt is made.
Windows 2000: This value is not supported.
SERVICE_CONTROL_TIMECHANGE
0x00000010Notifies a service that the system time has changed.
Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000: This control code is not supported.
SERVICE_CONTROL_TRIGGEREVENT
0x00000020Notifies a service registered for a service trigger event that the event has occurred.
Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000: This control code is not supported.

This parameter can also be a user-defined control code, as described in the following table.
Control codeMeaning
Range 128 to 255.The service defines the action associated with the control code.

dwEventType [in]
The type of event that has occurred. This parameter is used if dwControl is SERVICE_CONTROL_DEVICEEVENT, SERVICE_CONTROL_HARDWAREPROFILECHANGE, SERVICE_CONTROL_POWEREVENT, or SERVICE_CONTROL_SESSIONCHANGE. Otherwise, it is zero.
If dwControl is SERVICE_CONTROL_DEVICEEVENT, this parameter can be one of the following values:
DBT_DEVICEARRIVAL
DBT_DEVICEREMOVECOMPLETE
DBT_DEVICEQUERYREMOVE
DBT_DEVICEQUERYREMOVEFAILED
DBT_DEVICEREMOVEPENDING
DBT_CUSTOMEVENT
If dwControl is SERVICE_CONTROL_HARDWAREPROFILECHANGE, this parameter can be one of the following values:
DBT_CONFIGCHANGED
DBT_QUERYCHANGECONFIG
DBT_CONFIGCHANGECANCELED
If dwControl is SERVICE_CONTROL_POWEREVENT, this parameter can be one of the values specified in the wParam parameter of the WM_POWERBROADCAST message.
If dwControl is SERVICE_CONTROL_SESSIONCHANGE, this parameter can be one of the values specified in the wParam parameter of the WM_WTSSESSION_CHANGE message.
lpEventData [in]
Additional device information, if required. The format of this data depends on the value of the dwControl and dwEventType parameters. If dwControl is SERVICE_CONTROL_DEVICEEVENT, this data corresponds to the lParam parameter that applications receive as part of a WM_DEVICECHANGE message. If dwControl is SERVICE_CONTROL_POWEREVENT and dwEventType is PBT_POWERSETTINGCHANGE, this data is a pointer to a POWERBROADCAST_SETTING structure. If dwControl is SERVICE_CONTROL_SESSIONCHANGE, this parameter is a pointer to a WTSSESSION_NOTIFICATION structure.
lpContext [in]
User-defined data passed from RegisterServiceCtrlHandlerEx . When multiple services share a process, the lpContext parameter can help identify the service.
Return Value
The return value for this function depends on the control code received.
The following list identifies the rules for this return value:
In general, if your service does not handle the control, return ERROR_CALL_NOT_IMPLEMENTED. However, your service should return NO_ERROR for the following events even if your service does not handle them: SERVICE_CONTROL_INTERROGATE.
If your service handles SERVICE_CONTROL_DEVICEEVENT, return NO_ERROR to grant the request and an error code to deny the request.
If your service handles SERVICE_CONTROL_HARDWAREPROFILECHANGE, return NO_ERROR to grant the request and an error code to deny the request.
If your service handles SERVICE_CONTROL_POWEREVENT, return NO_ERROR to grant the request and an error code to deny the request.
For all other control codes your service handles, return NO_ERROR.
Remarks
When a service is started, its ServiceMain function should immediately call the RegisterServiceCtrlHandlerEx function to specify a HandlerEx function to process control requests. To specify the control codes to be accepted, use the SetServiceStatus and RegisterDeviceNotification functions.
The control dispatcher in the main thread of a service invokes the control handler function for the specified service whenever it receives a control request from the service control manager. After processing the control request, the control handler must call SetServiceStatus if the service state changes to report its new status to the service control manager.
The control handler function is intended to receive notification and return immediately. Therefore, it is best if the callback function saves its parameters and creates other threads to perform additional work. Your application must ensure that such threads have exited before stopping the service.
When the service control manager sends a control code to a service, it waits for the handler function to return before sending additional control codes to other services. The control handler must return within 30 seconds or the SCM returns an error. If a service must do lengthy processing when the service is executing the control handler, it should create a secondary thread to perform the lengthy processing, and then return from the control handler. This prevents the service from tying up the control dispatcher and blocking other services from receiving control codes.
The SERVICE_CONTROL_SHUTDOWN control code should only be processed by services that must absolutely clean up during shutdown, because there is a limited time (about 20 seconds) available for service shutdown. After this time expires, system shutdown proceeds regardless of whether service shutdown is complete. Note that if the system is left in the shutdown state (not restarted or powered down), the service continues to run.
If the service requires more time to clean up, it should send STOP_PENDING status messages, along with a wait hint, so the service controller knows how long to wait before reporting to the system that service shutdown is complete. However, to prevent a service from stopping shutdown, there is a limit to how long the service controller waits. If the service is being shut down through the Services snap-in, the limit is 125 seconds. If the operating system is rebooting, the time limit is specified in the WaitToKillServiceTimeout value of the following registry key:
HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control
Be sure to handle Plug and Play device events as quickly as possible; otherwise, the system may become unresponsive. If your event handler is to perform an operation that may block execution (such as I/O), it is best to start another thread to perform the operation asynchronously.
Services can also use the SetConsoleCtrlHandler function to receive shutdown notification. This notification is received when the running applications are shutting down, which occurs before services are shut down.
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinSvc.h (include Windows.h)
See Also
RegisterDeviceNotification
RegisterServiceCtrlHandlerEx
Service Control Handler Function
Service Functions
ServiceMain
SetServiceStatus
WM_DEVICECHANGE
WM_POWERBROADCAST
WM_WTSSESSION_CHANGE
POWERBROADCAST_SETTING
WTSSESSION_NOTIFICATION
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms683241(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:20:10