I have a COM component in an STA implemented with ATL Apartment
The exe is installed as a Windows service.
My client is also a COM component which is running also as a separate
Windows service but probably in an MTA.
I am experiencing the following problem: The client instantiates my
component on several threads concurently and calls my function. I see
that my function is executed always by the same thread (because of
STA). But before my function is completed, it will be called
(reentered) again. I actually see it on the trace lines.
How can I avoid or handle this kind of situation specially thinking
about the handling of global and static members?
My function is actually calling a function on a third COM component as
the code snippet shows.
Could you please help?
BSTR * pbstrVersion,
VARIANT * pvarInstallDate)
strParams.Format("UniqueID = %ld, ThreadID = %ld\n",
ERROR("WebService not initialized.\n");
struct Data lData;
HRESULT hr = S_OK;
lData = m_pWebService->getData(
TRACE("getData ok: softwareVersion:%s, installationDate:%s\n",
*pbstrVersion = ::SysAllocString(A2COLE(lData.softwareVersion));
pvarInstallDate->vt = VT_DATE;
HRESULT hr = ::VarDateFromStr(
if ( FAILED(hr) )
ERROR("Unable to convert date:%s\n",
catch (const _com_error& e)
hr = e.Error();
ERROR("getData failed: hr = %X, Desc = %s\n",
hr, (const char *)e.Description());