I'm using PHP to call an object on server with class COM, at IIS 7.
The object is well created, but when I'm using a method of it, PHP return this error:
PHP Fatal error: Uncaught exception 'com_exception' with message 'Parameter 5: Type mismatch.
The error occurs in the parameter $bd.
My PHP code:
$oem = new COM("LogicControlOEM.OEM_EjecutaOEM") or die("ERROR");
var_dump($oem);
$empresa = 1;
$usuario = 'XXX';
$pass = 'XXX';
$proveedor = '';
$servidor = 'XXXX';
$bd = 'example'; // I tried to putting a (string) and (String) before
$oem->InicializaOEM($empresa,
$usuario,
$pass,
$proveedor,
$servidor,
$bd);
var_dump($oem);
$oem = null;
I got the function that I want to use inside the component:
HRESULT InicializaOEM(
[in, out] short* intEmpresa,
[in, out] BSTR* sUserName,
[in, out] BSTR* sPassword,
[in, out, optional] BSTR* sProvider,
[in, out, optional] BSTR* sDataSource,
[in, out, optional] BSTR* sCatalog);
What type is BSTR and why only has problems with the last parameter? I think is a type of visual basic variable of string...
I tried those same parameters in a file .vbs and works fine.
It's a very strict signature for a COM method, don't know it's because of strict requirements or a bad design, you decide it.
out
s in the given IDL clarify that all of the parameters required to pass by reference with specific type, not variant.Even in an environment like VBScript where almost everything is COM variant, it would not possible to pass parameters by reference to such a method if there's no special handling in the COM library, because you can't declare strongly typed variables in VBScript.
Again in VBScript, there's a ByVal hack so it would be possible putting extra parentheses around the parameters knowing that you will not be able to access the parameters if modified within the COM method. But, this hack is not applicable in PHP's COM library unfortunately.
The best you can do is I think writing a COM library that wraps the
LogicControlOEM
namespace but accepts variant parameters everywhere.The easiest environment for creating such a library is Visual Basic 6.0 of course. Note that it's 32-bit only.
BTW No significant maintenance has been done in for PHP COM since late 2005. And based on experience I can say that
com_exception
error messages are not reliable to point the right parameter position most of the time.