Top  Previous  Next

You often need to cast pointers to objects into IDispatch* or IDispatch** when calling functions in the Inventor C++ COM API. Here are some examples, showing how to cast from various Inventor pointers to an IDispatch* :


Add a sketch based on a workplane:


   CComPtr<WorkPlane> pWorkPlane ;

   hRes = pSketches->Add (_variant_t((IDispatch*)pWorkPlane),




Add a workplane based on an existing workplane:


   CComPtr<WorkPlane> pWorkPlane... ;

   CComPtr<WorkPlane> pOffsetWorkPlane ;

   hRes = pWorkPlanesList->AddByPlaneAndOffset (_variant_t((IDispatch*)pWorkPlane),// "starting" plane

                                                CComVariant(kTubeDiam/2.0),        // how much to offset

                                                VARIANT_FALSE,                     // Construction?

                                                &pOffsetWorkPlane) ;               // Return value of this call



Add a workpoint based on a sketchpoint:


   CComPtr<SketchPoint> pSketchPoint... ;

   CComPtr<WorkPoint> pWorkPoint ;

   hRes = pWorkPointsList->AddByPoint (_variant_t((IDispatch*)pSketchPoint),VARIANT_FALSE,&pWorkPoint) ;

   if (FAILED(hRes) || (pWorkPoint == nullptr)) {

       return ReturnAndShowCOMError (hRes,L"AddWorkPointAtSketchPoint, Add workpoint failed") ; 




Create a proxy geometry from an occurrence and a workplane:


   CComPtr<WorkPlaneProxy> pWPProxyA ;

   pOccurrence->CreateGeometryProxy (pWorkPlaneA,(IDispatch**)&pWPProxyA) ;



Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)