Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

php - How to convert 8209 array object variant to VT_VARIANT

I am calling a COM object method that returns an array variant object of type 8209 in my PHP code.

$com_VArray = $com_Object->objectMethod; //Is a 8209 variant object

I want in the end to pass the converted VT_VARIANT object as a value for another COM object method which requires its input to be VT_VARIANT[12].

I am converting $com_VArray to a VT_VARIANT object variant type by issuing the following

$obj_VT_VARIANT = variant_cast($com_VArray, VT_VARIANT);

But then I get this following error

Fatal error: Uncaught exception 'com_exception' with message 'Variant type conversion failed: Type mismatch.' in C:xampphtdocswaterCompany eservoir.php:110 Stack trace #0 C:xampphtdocswaterCompany eservoir.php(110): variant_cast(Object(variant),12)#1{main} thrown in C:xampphtdocswaterCompany eservoir.php on line 110.

I have done some more reading on variant_cast here http://php.net/manual/en/function.variant-set-type.php but I have not made much significant headways.

I am using PHP 5.5.11.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

8209 is 0x2011 that signals an array of VT_UI1 elements.

When you want to convert it, you need to create an array of Variants and copy each element of the old type into it. When you copy the contents you can cast each VT_UI1 element into an VT_VARIANT type.

It is not and never allowed to cast arrays. Just try to learn the basisc of VARIANTs


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...