PHP - Using COM error message: Parameter 5: Type mismatch

北慕城南 提交于 2019-12-11 03:06:16

问题


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.


回答1:


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.

outs 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.



来源:https://stackoverflow.com/questions/44202766/php-using-com-error-message-parameter-5-type-mismatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!