servicemain函数仅在服务事件停止时启动

时间:2012-05-19 07:38:05

标签: c windows winapi service windows-services

我使用以下链接http://www.muukka.net/programming/service/Beeper%20Service.cpp来编写服务。但问题是,只有在请求服务停止时才会调用servicemain函数。

我想事先启动servicemain函数,检测连接的usb设备..我该怎么做..

1 个答案:

答案 0 :(得分:1)

在代码中:

  

SC_HANDLE service = CreateService(serviceControlManager,serviceName,   serviceName,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,    SERVICE_AUTO_START ,SERVICE_ERROR_IGNORE,路径,0,0,0,0,0);

更改为:

  

SC_HANDLE service = CreateService(serviceControlManager,serviceName,   serviceName,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,    SERVICE_DEMAND_START ,SERVICE_ERROR_IGNORE,路径,0,0,0,0,0);

还试试这个: http://msdn.microsoft.com/en-us/library/windows/desktop/bb540476%28v=vs.85%29.aspx