网站首页  词典首页

请输入您要查询的函数:

 

术语 servicemain
释义 ServiceMain
语法:
C++
VOID WINAPI ServiceMain(
__in DWORD dwArgc,
__in LPTSTR *lpszArgv
);
ServiceMain回调函数
为服务的切入点。
在LPSERVICE_MAIN_FUNCTION类型定义一个指向这个回调函数。 ServiceMain是一个占位符,一个应用程序定义的函数的名称。
参数
dwArgc [in]
在该lpszArgv数组参数的个数。
lpszArgv [in]
空端通过向StartService函数启动服务调用服务参数字符串。如果没有参数,此参数可以为NULL。否则,第一个参数(lpszArgv [0])是服务的名称,其次是任何其他参数(lpszArgv [1]通过lpszArgv [dwArgc - 1])。
如果用户手动启动服务,使用服务管理单元,从控制面板,从对话框中的服务(从服务属性来的lpszArgv参数的字符串管理单元中,右键单击该服务项,单击属性,然后在启动参数的参数。)
返回值
这个函数没有返回值。
备注
一个服务程序可以启动一个或多个服务。一个服务进程为每个服务,它可以启动SERVICE_TABLE_ENTRY结构。结构规定了该服务的服务名称和向ServiceMain函数的指针。
当服务控制管理器接收到一个请求启动一个服务,它启动服务进程(如果它尚未运行)。 The main thread of the service process calls the StartServiceCtrlDispatcher function with a pointer to an array of SERVICE_TABLE_ENTRY structures.然后,服务控制管理器发送一个请求,开始对这项服务的过程中服务控制调度。控制调度的服务创建一个新的线程来执行服务的ServiceMain函数正在启动。
在ServiceMain函数应立即调用RegisterServiceCtrlHandlerEx函数指定HandlerEx函数来处理控制请求。其次,它应该调用SetServiceStatus函数状态信息发送到服务控制管理器。经过这些调用,该函数应完成服务的初始化。不要试图开始在ServiceMain函数的另一项服务。
服务控制管理器(SCM)等待,直到服务报告的SERVICE_RUNNING地位。建议在这两份报告的服务,尽快地位,在系统需要与供应链管理互动的其他部分将在此期间封锁。有些功能可能需要与供应链管理的互动直接或间接的影响。
锁的供应链管理服务的初始化过程中控制数据库,因此,如果一个服务试图调用初始化期间StartService,电话将块。当服务报告,它已成功启动供应链管理,它可以调用StartService。如果该服务需要其他服务来运行,服务应设置所需的依赖关系。
此外,您不应该在服务初始化调用任何系统的功能。服务代码应调用系统功能的报告之后,才在SERVICE_RUNNING地位。
在ServiceMain函数应建立一个全球性事件,呼吁这一事件的RegisterWaitForSingleObject功能,并退出。这将终止线程运行的ServiceMain函数,但不会终止服务。当服务正在停止的服务控制处理程序应调用SERVICE_STOP_PENDING SetServiceStatus和信号此事件。从线程池线程将执行等待回调函数,这个函数应当执行清理任务,包括关闭全球活动,并与SERVICE_STOPPED呼吁SetServiceStatus。之后,该服务已停止,您不应该执行任何额外的服务代码,因为您可以引入竞争状态,如果服务收到启动控制和ServiceMain再次调用。请注意此问题是更可能发生多个服务共享一个进程。
实例
有关示例,请参见编写一ServiceMain函数。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinsvc.h(头文件:winuser.h)
参见
HandlerEx
RegisterServiceCtrlHandlerEx
RegisterWaitForSingleObject
服务函数
服务ServiceMain函数
SERVICE_TABLE_ENTRY
SetServiceStatus
StartServiceCtrlDispatcher
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==ServiceMain Callback Function
The entry point for a service.
The LPSERVICE_MAIN_FUNCTION type defines a pointer to this callback function. ServiceMain is a placeholder for an application-defined function name.
Syntax
C++
VOID WINAPI ServiceMain(
__in DWORD dwArgc,
__in LPTSTR *lpszArgv
);
Parameters
dwArgc [in]
The number of arguments in the lpszArgv array.
lpszArgv [in]
The null-terminated argument strings passed to the service by the call to the StartService function that started the service. If there are no arguments, this parameter can be NULL. Otherwise, the first argument (lpszArgv[0]) is the name of the service, followed by any additional arguments (lpszArgv[1] through lpszArgv[dwArgc-1]).
If the user starts a manual service using the Services snap-in from the Control Panel, the strings for the lpszArgv parameter come from the properties dialog box for the service (from the Services snap-in, right-click the service entry, click Properties, and enter the parameters in Start parameters.)
Return Value
This function does not return a value.
Remarks
A service program can start one or more services. A service process has a SERVICE_TABLE_ENTRY structure for each service that it can start. The structure specifies the service name and a pointer to the ServiceMain function for that service.
When the service control manager receives a request to start a service, it starts the service process (if it is not already running). The main thread of the service process calls the StartServiceCtrlDispatcher function with a pointer to an array of SERVICE_TABLE_ENTRY structures. Then the service control manager sends a start request to the service control dispatcher for this service process. The service control dispatcher creates a new thread to execute the ServiceMain function of the service being started.
The ServiceMain function should immediately call the RegisterServiceCtrlHandlerEx function to specify a HandlerEx function to handle control requests. Next, it should call the SetServiceStatus function to send status information to the service control manager. After these calls, the function should complete the initialization of the service. Do not attempt to start another service in the ServiceMain function.
The Service Control Manager (SCM) waits until the service reports a status of SERVICE_RUNNING. It is recommended that the service reports this status as quickly as possible, as other components in the system that require interaction with SCM will be blocked during this time. Some functions may require interaction with the SCM either directly or indirectly.
The SCM locks the service control database during initialization, so if a service attempts to call StartService during initialization, the call will block. When the service reports to the SCM that it has successfully started, it can call StartService. If the service requires another service to be running, the service should set the required dependencies.
Furthermore, you should not call any system functions during service initialization. The service code should call system functions only after it reports a status of SERVICE_RUNNING.
The ServiceMain function should create a global event, call the RegisterWaitForSingleObject function on this event, and exit. This will terminate the thread that is running the ServiceMain function, but will not terminate the service. When the service is stopping, the service control handler should call SetServiceStatus with SERVICE_STOP_PENDING and signal this event. A thread from the thread pool will execute the wait callback function; this function should perform clean-up tasks, including closing the global event, and call SetServiceStatus with SERVICE_STOPPED. After the service has stopped, you should not execute any additional service code because you can introduce a race condition if the service receives a start control and ServiceMain is called again. Note that this problem is more likely to occur when multiple services share a process.
Examples
For an example, see Writing a ServiceMain Function .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinsvc.h (include Windows.h)
See Also
HandlerEx
RegisterServiceCtrlHandlerEx
RegisterWaitForSingleObject
Service Functions
Service ServiceMain Function
SERVICE_TABLE_ENTRY
SetServiceStatus
StartServiceCtrlDispatcher
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms685138(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:23:01