Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have created my service in VC++ on windows XP. My application is having so many dll(more than 15). When I start service I receive above message immediatly. I read that when it takes more then 30 sec to start it gives above error but in my service error come immediatly. Can any one tell me solution to resolve this problem.
I have used file logging in main, servicemain, control method but log file is not created meaning those function are not getting called.


Can any one tell me solution for this problem.
Posted

I would guess the service exits immediately or something. I would bet it's problem with your code or the DLL search path.
It would be usefull to put some code used in startup
 
Share this answer
 
#define DLL_EXPORT_SERVICE
#include <iostream>
#include <windows.h>
#include <servicehandler.h>
#include <winservice.h>
#include <shmhandler.h>
#include <command.h>
#include <servicedefines>
#include <ipccommunication.h>

SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;
void ControlHandler(DWORD request) ;

WinService :: WinService( void ) : ServiceHandler(NULL)
{
}
WinService :: ~WinService( void )
{
}

void ServiceMain(int argc, char** argv)
{
int error;
WinService winService;
ServiceStatus.dwServiceType = SERVICE_WIN32;
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;
hStatus = RegisterServiceCtrlHandler("WinService", (LPHANDLER_FUNCTION)ControlHandler);
if (hStatus == (SERVICE_STATUS_HANDLE)0)
{
// Registering Control Handler failed
//fprintf(fp, "Code is starting winservice25\n");
return;
}
// Initialize Service
error = 0;//winService.InitService();
if (error)
{
// Initialization failed
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = -1;
SetServiceStatus(hStatus, &ServiceStatus);
//fprintf(fp, "Code is starting winservice26\n");
return;
}
// We report the running status to SCM.
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus (hStatus, &ServiceStatus);


winService.Start();
return;
}
int WinService::InitService()
{
_ServiceHandler = new ServiceHandler("dll");
return 0;
}

void WinService::Start()
{
ServiceHandler->Start();
}

void ControlHandler(DWORD request)
{
switch(request)
{
case SERVICE_CONTROL_STOP:
{
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hStatus, &ServiceStatus);
return;
}

case SERVICE_CONTROL_SHUTDOWN:
{
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hStatus, &ServiceStatus);
return;
}
default:
break;
}
// Report current status
SetServiceStatus (hStatus, &ServiceStatus);
return;
}

int main()
{

SERVICE_TABLE_ENTRY ServiceTable[2];
ServiceTable[0].lpServiceName = "WinService";
ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
ServiceTable[1].lpServiceName = NULL;
ServiceTable[1].lpServiceProc = NULL;
// Start the control dispatcher thread for our service
StartServiceCtrlDispatcher(ServiceTable);
}


ServiceHandler class is exported from another dll which internally used more then 10 dll. Please tell me mistake that I am doing.
I have tried to run this program by removing servicehandler class then code runs properlly
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900