everyone
I want to know how to debug the windows service start-up code in C.there are several questions like this but in C# but they are not what I need. So far,I can only attach to process to debug.Now I want to debug the main() function,how to do? The more detailed,the better.
Thanks so much.
My codes are below.
main function:
void main()
{
SERVICE_TABLE_ENTRY ServiceTable[2];
ServiceTable[0].lpServiceName = "MemoryStatus";
ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain; //ServiceMain
ServiceTable[1].lpServiceName = NULL;
ServiceTable[1].lpServiceProc = NULL;
StartServiceCtrlDispatcher(ServiceTable);
}
ServiceMain Function:
void ServiceMain(int argc, char** argv)
{
//...some codes....
hStatus = RegisterServiceCtrlHandler("MemoryStatus",(LPHANDLER_FUNCTION)ControlHandler);
//...some codes....
//the worker loop of a service
while(ServiceStatus.dwCurrentState == SERVICE_RUNNING)
{
char buffer[10];
sprintf(buffer,"login...");
int result = WriteToLog(buffer);
if (result)
{
ReportStatus(SERVICE_STOPPED,-1);
return;
}
Sleep(SLEEP_TIME);
}
return;
}
and control handle function:
void ControlHandler(DWORD request)
{
switch(request)
{
case SERVICE_CONTROL_STOP:
WriteToLog("Monitoring stopped.");
//...Report Status to SCM code....
return;
case SERVICE_CONTROL_SHUTDOWN:
WriteToLog("Monitoring stopped.");
//...Report Status to SCM code....
return;
default:
break;
}
//...Report Status to SCM code....
return;
}