ATL service crashes when being stopped by the system
-
My ATL service crashes when it is being stopped by the system (its startup mode is "automatic"). This happens only if the service is running on Windows XP and is being stopped automatically (not manually). The source code:
HRESULT CMyServiceModule::PostMessageLoop() { RevokeClassObjects(); LogEvent(_T("Service stopped")); CoUninitialize(); SetServiceStatus(SERVICE_STOPPED); // <--- this line causes the crash return CAtlServiceModuleT::PostMessageLoop(); }
The debugger shows that m_hServiceStatus is NULL. Thank you in advance for any ideas. -
My ATL service crashes when it is being stopped by the system (its startup mode is "automatic"). This happens only if the service is running on Windows XP and is being stopped automatically (not manually). The source code:
HRESULT CMyServiceModule::PostMessageLoop() { RevokeClassObjects(); LogEvent(_T("Service stopped")); CoUninitialize(); SetServiceStatus(SERVICE_STOPPED); // <--- this line causes the crash return CAtlServiceModuleT::PostMessageLoop(); }
The debugger shows that m_hServiceStatus is NULL. Thank you in advance for any ideas.Hi It's a bit weird since m_hServiceStatus is a member of the statically allocated CMyServiceModule class. Anyway, what I'll try to do is; see if the m_hServiceStatus is non-NULL when the PostMessageLoop function is entered. If so, RevokeClassObjects or CoUnitialize (or another thread) will be fiddling with the module object. If you can't find whatever code is setting the m_hServiceStatus to NULL, you may find it's address (say after the service is started) and set a breakpoint that monitors an address (ie. set a Condition to 'when (*(int*) 0x12345678) changes' and 0x12345678 is the address of the m_hServiceStatus data member). Are you sure it's not CoUnitialize causing the exception? - typically things will go bonkers if you still have outstanding COM references and call CoUninitialize. Could it be another app still has COM references to objects allocated by the ATL service? Martin