1 Reply Latest reply on Dec 5, 2012 11:42 PM by Artem Taturevych

    How to get the IDispatch object in C++

    Feng Wei

      I have following code:



      CComPtr<IModelDoc2> iSwModel;
                          if(iSwModel != NULL)
                                    long ActiveDocType;
                                    CComPtr<IModelDocExtension> iSwModelDocExtension;


      for the next step, I want to get the IMotionStudyManager object. I find the GetMotionStudyManager of iSwModelDocExtension returns a IDispatch object. What should I do?

        • Re: How to get the IDispatch object in C++
          Artem Taturevych

          Use QueryInterface to get the specific interface.



          IDispatch *pDisp;

          CComPtr<IModelDoc2> iSwDoc;

          CComPtr<IModelDocExtension> iSwExt;

          CComPtr<IMotionStudyManager> iMotionStudyMgr;


          HRESULT success = iSwApp->get_IActiveDoc2(&iSwDoc);

          success = iSwDoc->get_Extension(&iSwExt);

          success = iSwExt->GetMotionStudyManager(&pDisp);

          success = pDisp->QueryInterface(IID_IMotionStudyManager, (void **) &iMotionStudyMgr);



          Do not forget to import the .tlb library:


          #import "swmotionstudy.tlb" named_guids, no_namespace



          Artem Taturevych

          Application Engineer at Intercad


          Tel: +61 2 9454 4444