16,472
社区成员
发帖
与我相关
我的任务
分享
void WINAPI ServiceMain()
{
// Register the control request handler
status.dwCurrentState = SERVICE_START_PENDING;
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
LogEvent(_T("Register Service Success!"));
//注册服务控制
hServiceStatus = RegisterServiceCtrlHandler(szServiceName, ServiceStrl);
if (hServiceStatus == NULL)
{
LogEvent(_T("Handler not installed"));
return;
}
SetServiceStatus(hServiceStatus, &status);
status.dwWin32ExitCode = S_OK;
status.dwCheckPoint = 0;
status.dwWaitHint = 0;
status.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(hServiceStatus, &status);
//模拟服务的运行,10后自动退出。应用时将主要任务放于此即可
//int i = 0;
//while (runing)
//{
// ControlService(hService,SERVICE_CONTROL_INTERROGATE,&status)
// if(status.dwCurrentState != SERVICE_RUNNING)
// runing=false;
//}
//
// status.dwCurrentState = SERVICE_STOPPED;
// SetServiceStatus(hServiceStatus, &status);
// LogEvent(_T("Service stopped"));
}