I am trying to get windows service working using c++. The service doesnt do anything special @ the moment. The code that the service runs is
int main(int argc, char** argv) {
if (argc != 1) return -1;
ofstream fTestFile;
fTestFile.open("C:\\ABC\\ServiceTest.txt", ios::app);
fTestFile << "argc=" << argc << endl;
for (int i=0;i <argc;i++)
fTestFile << "argv " << i << "=: " <<argv[i] << endl;
for (int i=0; i<100000; i++) {
fTestFile << i << ",";
if (i % 50 == 0) fTestFile << "\n";
Sleep(10);
}
fTestFile << "\n";
return 0;
}
When I click "Start" via services.msc on this service, the service tries to start but fails with (1053 error Taking too long to respond). In the servicetest.txt file I see some data, like I see the debug statements and I see the numbers till 2663 or something.
Is there a step that I am missing, any help greatly appreciated.
Thank You
main
. You have to register a service control function and communicate with the service control manager. The error message you seeing is from the service control manager, who is saying "I ran the program but it's not responding to my messages. - Raymond Chen 2012-04-04 02:16
Your service needs to communicate with the service manager (services.exe) to report and update it's current status.
Read here http://msdn.microsoft.com/en-us/library/windows/desktop/ms687414%28v=vs.85%29.aspx
ServiceMain()
function, you have to have the main()
function initialize the service and start execution - André Caron 2012-04-04 02:20