【求助】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);
}