VARIANT and CComVariant |
Top Previous Next |
CComVariant is a C++ encapsulation of VARIANT.
They are more or less tagged unions.
An example of using CComVariant when programming in Inventor is in the many get_Item calls in for loops:
const int ikNumConstraints = pConstraintList->Count ; for (int j = 1 ; j <= ikNumConstraints ; j++) { CComPtr<AssemblyConstraint> pConstraint; hRes = pConstraintList->get_Item(CComVariant(j),&pConstraint) ; if (FAILED(hRes)) { TRACE (L"Could not get the constraint %d of the assembly, hr=%X\n",j,hRes); return ; }
TRACE (L"Got constraint %d\n",j); }
Look at that CComVariant(j) call. That is how you send an integer to get_Item when get_Item wants a VARIANT.
Note also that it all the get_Item things start at 1.
You can create an empty variant and a real double variant as illustrated below:
CComVariant varEmpty, varReal(0.0);
Or you can use a global constant empty variant like this.
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)