AnsweredAssumed Answered

Multithreading COM c++ addin

Question asked by Sandor Racz on Mar 3, 2016
Latest reply on Sep 10, 2018 by Sandor Racz

From a button press on my CDialog I create a thread. Then I try calling get_IActiveDoc2 from my ISldWorks ptr, but the ActiveDoc always comes back as junk.

CoInitialize always returns S_OK. Anyone know why this is happening?   

 

Thanks for any help!

 

STDMETHODIMP Exporter::ToolbarCallback0(void)

{

     AFX_MANAGE_STATE(AfxGetStaticModuleState());

     if(m_dlg == NULL)

     {

            m_dlg = new MyDialog(this, AfxGetMainWnd());

            m_dlg->Create(MyDialog::IDD);

      }

     m_dlg->ShowWindow(SW_SHOW);

}

 

MyDialog::ButtonEvent()

{

     ...

     CreateThread(NULL, 0, ExportThread, this,  0,  &dwThreadIdArray);

}

 

DWORD WINAPI ExportThread(LPVOID pParam)

{

     HRESULT result =  ::CoInitialize(0);

     MyDialog* dialog = (MyDialog*) pParam;

     CComPtr<ISldWorks> iSwApp = dialog ->GetSldWorksPtr();

    

     CComPtr<IModelDoc2> swModel;

     iSwApp->get_IActiveDoc2(&swModel);

     //swModel is NULL

}

Outcomes