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;
                          iSwApp->get_IActiveDoc2(&iSwModel);
        
                          if(iSwModel != NULL)
                          {
                                    long ActiveDocType;
                                    iSwModel->GetType(&ActiveDocType);
      
      
                                    CComPtr<IModelDocExtension> iSwModelDocExtension;
                                    iSwModel->get_Extension(&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

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444