Dadi
October 4th, 1999, 09:30 AM
The following thread code is taken from my source.
The 1st time I execute the thread everything is ok and the thread exits successfully.
On the 2nd thread execution, the Advise fails with: RPC_E_DISCONNECTED "0x80010108 The object invoked has disconnected from its clients."
Note: If running in STA, CoInitializeEx(NULL,COINIT_APARTMENTTHREADED) then everything is always OK.
Please Help - Thanx
Eldad Kuperman
eldadk@ti.com
UINT WINAPI ScriptThread(LPVOID pvData)
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
CComObject<CSquirtManagerEvents>* pMgrSink = NULL;
CComPtr<ISquirtManager> pManager;
DWORD dwCookie = 0;
HRESULT hr = CComObject<CSquirtManagerEvents>::CreateInstance(&pMgrSink);
if (SUCCEEDED(hr))
{
pMgrSink->AddRef();
hr = CoCreateInstance(CLSID_SquirtManager, NULL, CLSCTX_ALL, IID_ISquirtManager, (void**)&pManager);
if (SUCCEEDED(hr))
{
HRESULT hr = AtlAdvise(pManager, pMgrSink, IID__ISquirtManagerEvents, &dwCookie);
ASSERT(SUCCEEDED(hr)); // THIS LINE FAIL ON THE 2ND TIME
//...
hr = AtlUnadvise(pManager, IID__ISquirtManagerEvents, dwCookie);
}
pMgrSink->Release();
}
CoUninitialize();
return 0;
}
The 1st time I execute the thread everything is ok and the thread exits successfully.
On the 2nd thread execution, the Advise fails with: RPC_E_DISCONNECTED "0x80010108 The object invoked has disconnected from its clients."
Note: If running in STA, CoInitializeEx(NULL,COINIT_APARTMENTTHREADED) then everything is always OK.
Please Help - Thanx
Eldad Kuperman
eldadk@ti.com
UINT WINAPI ScriptThread(LPVOID pvData)
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
CComObject<CSquirtManagerEvents>* pMgrSink = NULL;
CComPtr<ISquirtManager> pManager;
DWORD dwCookie = 0;
HRESULT hr = CComObject<CSquirtManagerEvents>::CreateInstance(&pMgrSink);
if (SUCCEEDED(hr))
{
pMgrSink->AddRef();
hr = CoCreateInstance(CLSID_SquirtManager, NULL, CLSCTX_ALL, IID_ISquirtManager, (void**)&pManager);
if (SUCCEEDED(hr))
{
HRESULT hr = AtlAdvise(pManager, pMgrSink, IID__ISquirtManagerEvents, &dwCookie);
ASSERT(SUCCEEDED(hr)); // THIS LINE FAIL ON THE 2ND TIME
//...
hr = AtlUnadvise(pManager, IID__ISquirtManagerEvents, dwCookie);
}
pMgrSink->Release();
}
CoUninitialize();
return 0;
}