最近写一个服务,可是在Windows启动是,服务老是启动出错!
int main(int argc, char* argv[])
{
...
SERVICE_TABLE_ENTRYA   MyServicesTable[] = 

{ SERVICE_NAME, MyServiceMain  }, 
{ NULL,              NULL          } 
}; 

if (!StartServiceCtrlDispatcherA( MyServicesTable)) 

//老是在这里出错 0x00000427
printf("error!");
};
return  0
}void WINAPI MyServiceMain(DWORD argc, LPSTR *argv)
{
...
}请问有人知道该怎么解决吗?

解决方案 »

  1.   

    Windows 启动时,服务启动失败,
    事件查看器中
    描述:
    等待 MyService 服务的连接超时(30000 毫秒)。 
    可能是此函数出错
    StartServiceCtrlDispatcher
      

  2.   

    察看一下MyServiceMain函数,其内部一定有耗时操作.
      

  3.   

    //from MSDNIf a service runs in its own process, the main thread of the service process should immediately call StartServiceCtrlDispatcher. All initialization tasks are done in the service's ServiceMain function when the service is started. If multiple services share a process and some common process-wide initialization needs to be done before any ServiceMain function is called, the main thread can do the work before calling StartServiceCtrlDispatcher, as long as it takes less than 30 seconds. Otherwise, another thread must be created to do the process-wide initialization, while the main thread calls StartServiceCtrlDispatcher and becomes the service control dispatcher.