ATL 7.0 free-threaded Windows NT service does not create COM objects (320116)
The information in this article applies to:
- Microsoft Visual C++ 2005 Express Edition
- Microsoft Visual C++ .NET (2002)
This article was previously published under Q320116 SYMPTOMS When client applications try to create an instance of a
Component Object Model (COM) object in a free-threaded Windows NT service, the
applications time out, and you receive the following error message: (0x80080005): Server Execution Failed You can create instances of the COM objects as expected, when the
server is configured to run as a simple COM server. CAUSE When you start a Windows NT service that was written by
using Active Template Library 7.0 (ATL), the CAtlServiceModule::ServiceMain function sets the m_bDelayShutdown member to false to avoid starting a background thread that ends the process when
the last COM object in the service is released.
When the _ATL_FREE_THREADED macro is defined, the base CAtlServiceModule::PreMessageFilter function registers the server's COM objects with the
REGCLS_SUSPENDED flag, but does not call CoResumeClassObjects when the m_bDelayShutdown flag is set to false. WORKAROUND To work around this problem, override the CAtlServiceModule::PreMessageLoop function. In the override, call the base PreMessageLoop function, and then call CoResumeClassObjects when m_bDelayShutdown is set to false. The following are examples for attributed and non-attributed
code. Non-attributed
Code
class CAtlServiceModule : public CAtlServiceModuleT<CAtlServiceModule, IDS_SERVICENAME>
{
public :
DECLARE_LIBID(LIBID_AtlServiceLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ATLSERVICE, "{40264CD5-A316-4ED6-A2D1-2BA3D3210BCE}")
HRESULT PreMessageLoop(int nShowCmd)
{
HRESULT hr;
hr = CAtlServiceModuleT<CAtlServiceModule,IDS_SERVICENAME>::PreMessageLoop(nShowCmd);
// workaround
if (hr==S_OK && !m_bDelayShutdown)
hr = CoResumeClassObjects();
return hr;
}
}; Attributed Code
[ module(SERVICE, uuid = "{82B6FF93-10CB-4A0B-88F4-A41D17ADC84B}",
name = "AtrService",
helpstring = "AtrService 1.0 Type Library",
resource_name="IDS_SERVICENAME") ]
class CServiceModule
{
public:
HRESULT PreMessageLoop(int nShowCmd)
{
HRESULT hr;
hr = CAtlServiceModuleT<CServiceModule,IDS_SERVICENAME>::PreMessageLoop(nShowCmd);
// workaround
if (hr==S_OK && !m_bDelayShutdown)
hr = CoResumeClassObjects();
return hr;
}
}; STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
REFERENCESFor additional information about the CoRegisterClassObject function and the CoResumeClassObjects function, visit the following MSDN Web sites:
Modification Type: | Major | Last Reviewed: | 12/30/2005 |
---|
Keywords: | kbConsole kberrmsg kbATLServer kbbug kbpending kbService KB320116 kbAudDeveloper kbAudITPRO |
---|
|