Function calls in Autodesk Inventor C++ programming

Top  Previous  Next

Every COM C++ Inventor API method comes in 2 "flavors":

 

1.low level methods: that take output param as input and return HRESULT, for example hRes = get_Item (Index,&Pointer).
2.high level methods: that return the result directly and throw exceptions, for example Pointer = GetItem (Index)

 

A concrete example of the difference is the visibility of workaxes:

 

   // This "low level" version will not crash and you can look at the success or not via hRes

   hRes = pWorkAxis->put_Visible (vbVisib) ;

   if (FAILED(hRes)) {

       // Show some error message if you want

   }

 

   // This "high level" version will throw and exception and crash if something is wrong

   pWorkAxis->Visible = vbVisib ;

 

 

There are other functions which are high and low distinguished by whether or not they have Method... in front of the name, high level methods are usually prefixed "Method".

 

Some examples :

 

   HRESULT hRes = pWorkPlanesList->get_Item (CComVariant(1),&pWorkPlane) ; // low level version

   WorkPlanePtr pWorkPlane = pWorkPlanesList->GetItem (CComVariant(1)) ; // high level version

 

 

...and...

 

   HRESULT hRes = pConstraintList->AddAngleConstraint (...etc...,&pAngConstraint) ; // low level version

   AngleConstraintPtr pAngConstraint = pConstraintList->MethodAddAngleConstraint(...etc...) ; // high level version

 

Note that with "low level" versions you often pass the address of a pointer which is the "return value" of the function.

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