我把服务主程序的代码贴出来,求指导://服务入口点函数

void WINAPI Service_Main(DWORD dwArgc, LPTSTR *lpszArgv)
{
//初始化 SERVICE_STATUS 结构中的成员
ssStatus.dwServiceType=SERVICE_WIN32_OWN_PROCESS;

ssStatus.dwControlsAccepted=SERVICE_ACCEPT_STOP;

ssStatus.dwCurrentState= SERVICE_STOPPED;

ssStatus.dwServiceSpecificExitCode=0;

ssStatus.dwCheckPoint=0;
ssStatus.dwWin32ExitCode=0;
ssStatus.dwWaitHint=0;

//注册服务控制处理函数
sshStatusHandle=RegisterServiceCtrlHandler(TEXT(SZSERVICENAME),Service_Ctrl);
//如果注册失败
if(!sshStatusHandle)
{
goto cleanup;
return;
}
//更新服务状态
if(!ReportStatusToSCMgr(
SERVICE_START_PENDING,//服务状态,The service is starting.
NO_ERROR, //退出码
3000)) //等待时间
goto cleanup; //更新服务状态失败则转向 cleanup
ServiceStart(dwArgc,lpszArgv);//具体的服务程序
return;
cleanup:
//把服务状态更新为 SERVICE_STOPPED,并退出。
if(sshStatusHandle)
(void)ReportStatusToSCMgr(SERVICE_STOPPED,dwErr,0);
}
请问哪里不对呢???

慕妹3146593
浏览 99回答 2
2回答

蝴蝶刀刀

// NT服务程序的入口函数void WINAPI ServiceMain(DWORD argc, LPSTR *argv){//DWORD status;//DWORD specificError;// 注册服务控制SKServer*NTSObj;NTSObj = (SKServer *)SKServerID;ServiceStatusHandle = RegisterServiceCtrlHandlerA(NTSObj->NTSName, ServiceCtrlHandler);ServiceStatus.dwServiceType= SERVICE_WIN32_OWN_PROCESS;ServiceStatus.dwCurrentState= SERVICE_START_PENDING;ServiceStatus.dwControlsAccepted= SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN;ServiceStatus.dwWin32ExitCode= 0;ServiceStatus.dwServiceSpecificExitCode= 0;ServiceStatus.dwCheckPoint= 0;ServiceStatus.dwWaitHint= 0;SetServiceStatus(ServiceStatusHandle, &ServiceStatus);if(NTSObj->OnStart!=NULL){NTSObj->OnStart();}ServiceStatus.dwCurrentState= SERVICE_RUNNING;SetServiceStatus(ServiceStatusHandle, &ServiceStatus);NTSObj->IsExit = FALSE;while(!NTSObj->IsExit){Sleep(100);}return;}// NT服务程序的服务控制处理函数void WINAPI ServiceCtrlHandler(DWORD Opcode){SKServer*NTSObj;NTSObj = (SKServer *)SKServerID;switch(Opcode){case SERVICE_CONTROL_PAUSE:if(NTSObj->OnPause!=NULL){NTSObj->OnPause();}ServiceStatus.dwCurrentState = SERVICE_PAUSED;SetServiceStatus(ServiceStatusHandle,&ServiceStatus);break;case SERVICE_CONTROL_CONTINUE:if(NTSObj->OnStart!=NULL){NTSObj->OnStart();}ServiceStatus.dwCurrentState = SERVICE_RUNNING;SetServiceStatus(ServiceStatusHandle,&ServiceStatus);break;case SERVICE_CONTROL_STOP:ServiceStatus.dwWin32ExitCode = 0;ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;ServiceStatus.dwCheckPoint = 0;ServiceStatus.dwWaitHint = 0;SetServiceStatus (ServiceStatusHandle,&ServiceStatus);if(NTSObj->OnStop!=NULL){NTSObj->OnStop();}ServiceStatus.dwCurrentState = SERVICE_STOPPED;SetServiceStatus(ServiceStatusHandle,&ServiceStatus);NTSObj->IsExit=TRUE;break;case SERVICE_CONTROL_INTERROGATE:break;}return;}

MYYA

这个问题好复杂。我也试过错误1053,后来发现是因为dll的路径放错了。因为系统服务的工作路径在system32。
打开App,查看更多内容
随时随地看视频慕课网APP