How to pass a variant object type 16396 in a COM m

2019-04-17 04:40发布

问题:

I have in my PHP code, a COM object '$com_myObject' with a method 'myObjectMethod' which after I run

com_print_type info($com_myObject);

on it, it shows that it has the method 'myObjectMethod' declared as shown below

myObjectMethod(/* VT_VARIANT [12] [in] */ $RawData) { /* Processes entered object data */ }

In my code I am having another function return a variant object '$myInputObject' of type value 16396. I plan to use '$myInputObject' as the input value for 'myObjectMethod' method.

print variant_get_type($myInputObject);  //returns 16396

I am retrieving the value for '$myInputObject' as shown below from this other COM function i.e 'ofunction' .

$myInputObject = $com_myObject->ofunction;

I am assuming that from 'myObjectMethod' method declaration I am supposed to pass a VT_VARIANT object i.e. a variant type 12 but what my other function 'ofunction' returns which is supposed to be the input value for 'myObjectMethod' is a variant object of type 16396.

I have tried to convert the variant object of type 16396 to a variant object of type 12 as shown below

$com_myObject->myObjectMethod(variant_cast($myInputObject, VT_VARIANT));

but I am getting the following error.

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