robin83
February 24th, 2006, 07:03 PM
Hi,
I have an addin which automates an instace of a cad program (Solid Edge). The interface to the application is known in my addin. Now I wanted to create a worker thread to do something with Solid Edge. I used a Stream to get the interface into the thread. Problem occurs with the first call to the interface. The program doesn't crash but the thread hangs. UI runs just fine. But the method of the interface doesn't return. Any ideas?
The following is my (simplified) code:
CHelper::CHelper(ApplicationPtr pAppPtr)
{
CoInitialize(NULL);
HRESULT res = CoMarshalInterThreadInterfaceInStream(__uuidof(ApplicationPtr),
(LPUNKNOWN)pAppPtr, &m_pStream);
}
CHelper::~CHelper(){ CoUninitialize (); }
UINT threadCreate (LPVOID pParam)
{
CoInitialize(NULL);
CHelper* pHelper = (CHelper*)pParam;
ApplicationPtr pAppPtr;
HRESULT hr = CoGetInterfaceAndReleaseStream(pHelper->GetStream(),
__uuidof(ApplicationPtr), (void**) &pAppPtr);
if (SUCCEEDED(hr))
{
//The thread hangs on the following line
DocumentsPtr pDocs = pAppPtr->GetDocuments();
//...
}
CoUninitialize()
return 0;
}
void CHelper::DoCreate(int &nUniqueID, CString &strCreatedPart)
{
//start the Thread:
CWinThread *pthreadCreate = AfxBeginThread (threadCreate, this);
//... wait for the thread and do some other stuff
}
Best regards,
Robin.
I have an addin which automates an instace of a cad program (Solid Edge). The interface to the application is known in my addin. Now I wanted to create a worker thread to do something with Solid Edge. I used a Stream to get the interface into the thread. Problem occurs with the first call to the interface. The program doesn't crash but the thread hangs. UI runs just fine. But the method of the interface doesn't return. Any ideas?
The following is my (simplified) code:
CHelper::CHelper(ApplicationPtr pAppPtr)
{
CoInitialize(NULL);
HRESULT res = CoMarshalInterThreadInterfaceInStream(__uuidof(ApplicationPtr),
(LPUNKNOWN)pAppPtr, &m_pStream);
}
CHelper::~CHelper(){ CoUninitialize (); }
UINT threadCreate (LPVOID pParam)
{
CoInitialize(NULL);
CHelper* pHelper = (CHelper*)pParam;
ApplicationPtr pAppPtr;
HRESULT hr = CoGetInterfaceAndReleaseStream(pHelper->GetStream(),
__uuidof(ApplicationPtr), (void**) &pAppPtr);
if (SUCCEEDED(hr))
{
//The thread hangs on the following line
DocumentsPtr pDocs = pAppPtr->GetDocuments();
//...
}
CoUninitialize()
return 0;
}
void CHelper::DoCreate(int &nUniqueID, CString &strCreatedPart)
{
//start the Thread:
CWinThread *pthreadCreate = AfxBeginThread (threadCreate, this);
//... wait for the thread and do some other stuff
}
Best regards,
Robin.