PHP to COM parameter passing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dolikeme
Forum Newbie
Posts: 2
Joined: Sat May 04, 2002 11:55 pm

PHP to COM parameter passing

Post by dolikeme »

Hello,

I recently got into PHP/COM and so I created a VB6 COM DLL to use as a wrapper for some FinCAD DLL's I need to call, but having problems in the area of parameter passing into and out of the VB wrapper on three specific issues. I also tested a IIS/ASP version of this script which works fine (or as expected) with this COM, but I can't use ASP for this project.

Problem:

1) I can only receive output data from the DLL function thru a single Function result value and not thru function parameters used by reference.

2) I can not pass a PHP array into DLL function, my every attempt is met with 'Invoke() failed: Type mismatch.'

3) I can not receive an array as a result of calling a function, although VB 6 allows passing arrays as result of functions.

I'm posting my sample COM object and working ASP and broken PHP which I'm using to test this COM wrapper.

My setup is: Win2K, IIS5, PHP 4.0.5 installed as CGI

VB6 COM PROGRAM:
================
Public Function foo(ByVal in_var As Variant, ByRef out_arr() As Variant, ByRef out_var As Variant) As Variant

' just do something

' swap input/ouput array elements
t = out_arr(0)
out_arr(0) = out_arr(1)
out_arr(1) = t
out_var = in_var ' update output parm with input parm
foo = in_var ' return input parameter as function value

End Function



WORKING ASP SCRIPT:
====================
<% Option Explicit

dim ob
dim arr(1)
dim invar
dim outvar
dim funcvalue

invar = 123
outvar = 0
arr(0) = 11
arr(1) = 22

Set ob = CreateObject("COMTEST.Tester")
funcvalue = ob.foo( invar, (arr) , outvar )

Set ob = Nothing

%>

<HEAD>
<TITLE>ASP/COM Tester</TITLE>
</HEAD>
<BODY>
<%
Response.Write "<P>ASP COMTEST.Tester.foo(invar=123,arr=(11,22),outvar=0) expected funcvalue=123, invar=123, arr(0)=22, arr(1)=11, outvar=123"
Response.Write "<P>ASP COMTEST.Tester.foo(invar=123,arr=(11,22),outvar=0) received funcvalue=" & funcvalue & ", invar=" & invar & ", arr(0)=" & arr(0) & ", arr(1)=" & arr(1) & ", outvar=" & outvar
%>
</BODY>




NON-WORKING PHP SCRIPT:
=======================
<?
$invar = "123";
$outvar = "0";
$arr = Array(0,0);
$arr[0] = "11";
$arr[1] = "22";

$ob = new COM("COMTEST.Tester");
$funcvalue = $ob->foo( $invar, &$arr[], &$outvar );

unset($ob);

?>

<HEAD>
<TITLE>PHP/COM Tester</TITLE>
</HEAD>
<BODY>
<?
echo "<P>PHP COMTEST.Tester.foo(invar=123,arr=(11,22),outvar=0) expected funcvalue=123, invar=123, arr(0)=22, arr(1)=11, outvar=123";
echo "<P>PHP COMTEST.Tester.foo(invar=123,arr=(11,22),outvar=0) received funcvalue=" . $funcvalue . ", invar=" . $invar . ", arr[0]=" . $arr[0] . ", arr[1]=" . $arr[1] . ", outvar=" . $outvar;
?>
</BODY>




WHAT AM I DOING WRONG?
PLEASE, HELP
Last edited by dolikeme on Tue May 07, 2002 10:22 pm, edited 1 time in total.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Actually, I believe in PHP 4.0.5, it didn't have support for SafeArrays or Enums when dealing with COM.

Check the ChangeLog, and upgrade to the newest PHP.
dolikeme
Forum Newbie
Posts: 2
Joined: Sat May 04, 2002 11:55 pm

Post by dolikeme »

OK, I upgraded to 4.1.1 - there seems to be no later COM fixes that would apply and still - problems remain:

There supposed to be a way to pass PHP vaiablas and single-dimentional arrays to COM'ed DLL's by reference. My every attempt to do that in PHP failed so far, but worked in ASP. Could someone post an example or tell me what's wrong wih mine?

My COM:
============================

Public Function foo(ByVal in_var As Variant, ByRef out_arr() As Variant, ByRef out_var As Variant) As Variant
Dim t
' just do something

' swap input/ouput array elements
t = out_arr(0)
out_arr(0) = out_arr(1)
out_arr(1) = t
out_var = in_var ' update output parm with input parm
foo = in_var ' return input parameter as function value

End Function



My PHP:
============================
[syntax=php]<?
$invar = "123";
$outvar = "0";
$arr = Array(0,0);
$arr[0] = "11";
$arr[1] = "22";

$ob = new COM("COMTEST.Tester");
$funcvalue = $ob->foo( $invar, &$arr, &$outvar );
?>
<HTML>
<HEAD>
<TITLE>PHP/COM Tester</TITLE>
</HEAD>
<BODY>
<?
echo "<P>PHP COMTEST.Tester.foo(invar=123,arr=(11,22),outvar=0) <b>expected</b> funcvalue=123, invar=123, arr(0)=22, arr(1)=11, outvar=123";
echo "<P>PHP COMTEST.Tester.foo(invar=123,arr=(11,22),outvar=0) <b>received</b> funcvalue=" . $funcvalue . ", invar=" . $invar . ", arr[0]=" . $arr[0] . ", arr[1]=" . $arr[1] . ", outvar=" . $outvar;

unset($ob);

?>
</BODY>
</HTML>[/syntax]
maxi
Forum Newbie
Posts: 10
Joined: Tue Apr 29, 2003 3:46 pm
Location: Buenos Aires, Argentina

Post by maxi »

I have the same trouble passing reference variables to a COM object which are VARIANT type.
I posted a topic in the forum "Com support for Windows" but I didn't get the expected answer.
If you get the solution, please post it to the forum.
Post Reply