How to read the contents of a VARIANT ?
-
Hi, I can not find out how to read what is in a VARIANT, which is the result of calling a method GetAllProperties. The doc of this method only specifies that a VARIANT is returned. It should contain some kind of strings. I tried this : VARIANT names; _variant_t v1; VARTYPE vtype; long ix; ... x->GetAllProperties(&names); if (V_ISARRAY(&names)) { SafeArrayGetVartype(names.parray,&vtype); // this returns 0x0800 in vtype, so I assume it is an array of _variant_t !!! for (ix=0;ix
-
Hi, I can not find out how to read what is in a VARIANT, which is the result of calling a method GetAllProperties. The doc of this method only specifies that a VARIANT is returned. It should contain some kind of strings. I tried this : VARIANT names; _variant_t v1; VARTYPE vtype; long ix; ... x->GetAllProperties(&names); if (V_ISARRAY(&names)) { SafeArrayGetVartype(names.parray,&vtype); // this returns 0x0800 in vtype, so I assume it is an array of _variant_t !!! for (ix=0;ix
You're assuming
v1
is a string. It maybe something else (you have to check theVARIANT
'svt
field). Moreover, why don't you check theSafeArrayGetElement
return value? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, I can not find out how to read what is in a VARIANT, which is the result of calling a method GetAllProperties. The doc of this method only specifies that a VARIANT is returned. It should contain some kind of strings. I tried this : VARIANT names; _variant_t v1; VARTYPE vtype; long ix; ... x->GetAllProperties(&names); if (V_ISARRAY(&names)) { SafeArrayGetVartype(names.parray,&vtype); // this returns 0x0800 in vtype, so I assume it is an array of _variant_t !!! for (ix=0;ix
LindeA wrote:
_bstr_t s1(v1);
In addition to checks suggested by
CPallini
, I suggest to you to readVARIANT's
doucmentation. If it really contains strings, it can be used asv1.bstr
. -
You're assuming
v1
is a string. It maybe something else (you have to check theVARIANT
'svt
field). Moreover, why don't you check theSafeArrayGetElement
return value? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]I did what you suggest : the return value of SafeArrayGetElement is S_OK v1.vt = 0x95d4 I have seen a VB example using this GetAllProperties method, and there they simply access it with names(i), and treat it as a string ( it stands for a Property Name ) How can I translate this into C++ ?