Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows service VC++
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 7-Jul-11 18:25pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

#define DLL_EXPORT_SERVICE
#include
#include
#include
#include
#include
#include
#include
#include
 
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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 550
1 OriginalGriff 419
2 Maciej Los 300
3 PIEBALDconsult 180
4 King_Fisher 160
0 Sergey Alexandrovich Kryukov 11,069
1 OriginalGriff 5,743
2 Maciej Los 5,649
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web02 | 2.8.141030.1 | Last Updated 11 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100