I am able to install and start the service perfectly without any error by following those instruction.
In the example given, the service will just running and do nothing because there's nothing inside while { } statement in ServiceMain(DWORD argc, LPTSTR *argv) function. Therefore, i add some code inside the while statement. After added in the code, I'm able to install the service, but when i try to start the service it said :
"System error 1067 has occurred. The process terminated unexpectedly". What's actually happened anyone ? The following is my code in ServiceMain function:
Code:
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
DWORD status;
DWORD specificError;
m_ServiceStatus.dwServiceType = SERVICE_WIN32;
m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
m_ServiceStatus.dwWin32ExitCode = 0;
m_ServiceStatus.dwServiceSpecificExitCode = 0;
m_ServiceStatus.dwCheckPoint = 0;
m_ServiceStatus.dwWaitHint = 0;
m_ServiceStatusHandle = RegisterServiceCtrlHandler("ServiceC",
ServiceCtrlHandler);
if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)
{
return;
}
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
m_ServiceStatus.dwCheckPoint = 0;
m_ServiceStatus.dwWaitHint = 0;
if (!SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus))
{
}
bRunning = true;
while (bRunning)
{
// The problem occur here, if i comment out all the codes within the while loops it works perfectly
TestClassr *tc;
tc=new TestClass();
tc->Resume();
bRunning = false;
delete tc;
tc = 0;
}
return;
}
For you all information, TestClass is a class that is generated from PThread.
PThread = one of the Class from Openh323 (www.openh323.org)
Hope somebobody can help me out. Thanks in advance
Last edited by cppnewbie81; July 4th, 2007 at 01:18 AM.
OK i think I know what cause the problem, but too bad i don't know the solution .. I have a console application which is run perfectly before, therefore I put in what is already running inside "ServiceMain" function. And i believe calling the Thread class inside the ServiceMain function is what cause the problem (as shown following)
Code:
TestClass *tc;
tc=new TestClass();
tc->Resume()
I try to create another TestClass which is dervied from PObject instead of PThread, and it works perfectly. But this is not what i want, i want to call a Thread Class with a main loop that listen for request and, for each request, spawn a thread to handle the request. Any solution ? IM in crying need now, hope someone can help. Thanks
First, what that thread exactly does? It might terminate the process as well, especially if it's done in the same manner the ServiceMain is - no decent return value checking.
Second, it would be good take a look at ServiceCtrlHandler which is really important for a service life cycle.
Third, the first developer's friend is an off-line debugging (as logging to a file, etc.), and post-mortem analysis is the second one.
MrBeans - Thanks for the source code, but where should i put the code that i want service to process ? I try to look into each of the files but can't found it ...
Igor - The TestClass has a main loop that listen for request and, for each request, spawn a thread to handle the request. At first i thought it was the function inside the thread that terminated the service, therefore i comment out all the code inside each of the function. But the same error still occured.
And as i mention on the above post, here's where it cause the error :
Code:
while (bRunning)
{
// The problem occur here, if i comment out all the codes within the while loops it works perfectly
TestClassr *tc;
tc=new TestClass();
tc->Resume();
bRunning = false;
delete tc;
tc = 0;
}
I log the error in a log file, and here's where the service "DEAD" :
Return code
ERROR_FAILED_SERVICE_CONTROLLER_CONNECT Description
Typically, this error indicates that the program is being run as a console application rather than as a service.
Sounds like (as Igor quoted) there is some console I/O going in. Search all of your code for any such things (cout, cin, printf, etc).
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010 In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.