How to pass a variant object type 16396 in a COM method that requires an input value of a VT_VARIANT [12]
Asked Answered
R

0

0

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.

Rarebit answered 18/2, 2017 at 21:44 Comment(8)
16396 is VT_BYREF | VT_VARIANT (msdn.microsoft.com/library/cc237865.aspx). It just means it's a VARIANT structure that holds a pointer to another VARIANT. So the VARIANT you're looking for is just a pointer away. How did you get that ref'd VARIANT in the first place? Have you tried variant_set_type instead of variant_cast? Or maybe use an intermediary php zval variable and create a new variant using variant_set? In c++, it's fairly easy to do, but I'm not familiar with php, so I can't help you much more.Bramlett
True indeed 16396 is is VT_BYREF | VT_VARIANT. I get it when I call this COM object function $com_myObject->ofunction; I am still getting the same results with $com_myObject->myObjectMethod(variant_set_type($myInputObject, VT_VARIANT)); I wouldn't mind you showing me how to do it in C++. I am at that point I can just try and learn anything to get this behind my pastRarebit
In C++, this is how I could "dereference" the VARIANT: pastebin.com/8BWQQVPj maybe you can write a php extension in C++. I would be suprised there's no trick available directly in php w/o having to write such an extension, but like I said, I'm no php expert. In fact such a function could be added to the list of variant_* function that php supports... dereferencing is a common thing in COM automationBramlett
@Simon Mourier thank you for this insight. It points me in the right direction. I will pore the internet and find out how I could dereference a VARIANT in php.I am hopping I will not have to go to the extend of writing a php extension in C++.Rarebit
@SimonMourier This question appears unresolved as there are no posted answers. However, your comments seem to be the closest thing to an answer (which future readers will benefit from). Please consolidate your comments into an answer so that: this question appears answered, future readers don't have to read all of the comments to glean vital wisdom, and JosephMwema can potentially award your answer with a green tick.Bolten
@Bolten - my comments are really not an answer, it's more to josephmwema to answer his own question if he ever found an answerBramlett
@JosephMwema If you found your solution please share it (and mark it) as an answer so that other may benefit from your success.Bolten
Hi @Bolten I did not make any headways with it though the comments posted here helped increase my little understanding of VT VARIANTs. I posted and shared this question in various PHP groups and forums outside SO and no one took it up. PHP.NET themselves are too busy to notice my e-mails. I paused working on the project until I figure out how to go about passing VT VARIANTs as values or references in COM object methods in PHP. The alternative is to code in ASP.NET where it is easy to call dlls but I wanted it in PHP. If I get a solution trust me I will share it here.Rarebit

© 2022 - 2024 — McMap. All rights reserved.