| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 605 人关注过本帖
标题:【求助】1053 服务响应问题
只看楼主 加入收藏
gpp6025
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2010-7-8
结帖率:84.62%
收藏
已结贴  问题点数:30 回复次数:2 
【求助】1053 服务响应问题
小弟在写服务的时候是将服务控制和主服务程序分开写的,在启动的时候一开始绿色的条读的很快但到了一半的时候就停了下来然后就是1053错误,服务显示为启动状态,但是没见执行服务的内容,程序如下望各位大大的门帮个忙~~小弟不胜感激!!
#include "stdafx.h"
#include "Windows.h"

#pragma comment(lib,"ws2_32.lib")
#define APPSNAME      "servicername"
#define INSNAME  "inservicename"

SERVICE_STATUS              sStatus;
SERVICE_STATUS_HANDLE  sStatusHandle;
DWORD                       dwErr=0;

void  WINAPI  ServiceEntry(DWORD dwArgc, LPTSTR *lpszArgv);
void  WINAPI  Service_Ctrl(DWORD dwCtrlCode);
BOOL ReportStatusToSCMgr(DWORD dwCurrentState,DWORD dwWin32ExitCode,DWORD dwWaitHint);

void ServiceRun(DWORD dwArgc,LPTSTR* lpszArgv);

int _tmain(int argc, _TCHAR* argv[])
{
     SERVICE_TABLE_ENTRY dispatchTable[]=
     {
         {TEXT(INSNAME),(LPSERVICE_MAIN_FUNCTION)ServiceEntry},
         {NULL,NULL}
     };
    if(!StartServiceCtrlDispatcher(dispatchTable))
    {
        printf("the service is fail %d",GetLastError());
    }
    return 0;
}

void  WINAPI    ServiceEntry(DWORD dwArgc, LPTSTR *lpszArgv)
{
    sStatusHandle=RegisterServiceCtrlHandler(TEXT(INSNAME),Service_Ctrl);
    if(!sStatusHandle)
    {
        printf("the ctrhandler reg fail %d",GetLastError());
        return;
    }
     sStatus.dwControlsAccepted = SERVICE_ALL_ACCESS;
     sStatus.dwServiceType=SERVICE_WIN32_OWN_PROCESS;
     sStatus.dwServiceSpecificExitCode=0;
     //更新服务状态 :服务开始,退出码,等待时间
     if(!ReportStatusToSCMgr(SERVICE_START_PENDING,NO_ERROR,0))
     {
         return;
     }
     ServiceRun(dwArgc,lpszArgv); //具体服务内容开始
     return;
}

void ServiceRun(DWORD dwArgc,LPTSTR* lpszArgv)
{
    WSADATA wsa;
    struct sockaddr_in localsk;
    SOCKET sket;
    WSAStartup(MAKEWORD(2,2),&wsa);
    sket=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    localsk.sin_addr.S_un.S_addr=INADDR_ANY;
    localsk.sin_family=AF_INET;
    localsk.sin_port=6086;
    bind(sket,(LPSOCKADDR)&localsk,sizeof(localsk));
    listen(sket,5);
    return;
}

void  WINAPI  Service_Ctrl(DWORD dwCtrlCode)
{
    switch(dwCtrlCode)
    {
        case SERVICE_CONTROL_PAUSE:
            ReportStatusToSCMgr(SERVICE_STOP_PENDING,NO_ERROR,0);//first updata service stop
            sStatus.dwCurrentState=SERVICE_PAUSED;
            break;
        case SERVICE_CONTROL_STOP:
            ReportStatusToSCMgr(SERVICE_STOP_PENDING,NO_ERROR,0);
            sStatus.dwCurrentState=SERVICE_STOPPED;
            break;
        case SERVICE_CONTROL_CONTINUE:
            ReportStatusToSCMgr(SERVICE_STOP_PENDING,NO_ERROR,0);
            sStatus.dwCurrentState=SERVICE_RUNNING;
            break;
        default:
            break;
    }
    ReportStatusToSCMgr(sStatus.dwCurrentState,NO_ERROR,0);//after reset, updata the service status
    return;
}


BOOL ReportStatusToSCMgr(DWORD dwCurrentState,DWORD dwWin32ExitCode,DWORD dwWaitHint)
{
    sStatus.dwWin32ExitCode     = dwWin32ExitCode;
    sStatus.dwCheckPoint         = 0;
    sStatus.dwWaitHint         = dwWaitHint;
    sStatus.dwCurrentState=dwCurrentState;
    return SetServiceStatus(sStatusHandle,&sStatus);
}
搜索更多相关主题的帖子: 不胜感激 comment include 
2011-08-09 08:57
gpp6025
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2010-7-8
收藏
得分:0 
自己顶下谁能帮忙解答下啊~~~
2011-08-10 14:38
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:21 
The service did not respond to the start or control request in a timely fashion.
2011-08-10 16:32
快速回复:【求助】1053 服务响应问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037659 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved