PHP-使用COM错误消息:参数5:类型不匹配 [英] PHP - Using COM error message: Parameter 5: Type mismatch

查看:210
本文介绍了PHP-使用COM错误消息:参数5:类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP在IIS 7上的类为COM的服务器上调用对象。

I'm using PHP to call an object on server with class COM, at IIS 7.

对象创建良好,但是当我使用它的方法,PHP返回此错误:

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.

错误发生在参数$ bd中。

The error occurs in the parameter $bd.

我的PHP代码:

$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);

BSTR是什么类型,为什么最后一个参数只有问题?我认为是字符串的一种视觉基本变量...

What type is BSTR and why only has problems with the last parameter? I think is a type of visual basic variable of string...

我在.vbs文件中尝试了相同的参数,并且工作正常。

I tried those same parameters in a file .vbs and works fine.

推荐答案

对于COM方法来说,它是非常严格的签名,不知道是由于严格的要求还是设计不好,您决定了。

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 澄清了通过引用使用特定类型传递的所有参数

outs in the given IDL clarify that all of the parameters required to pass by reference with specific type, not variant.

即使在VBScript这样的环境中,几乎所有内容都是COM变体,也无法通过引用这样的方法传递参数在COM库中没有特殊处理,因为您不能在VBScript中声明强类型变量。

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.

在VBScript中同样存在ByVal hack,因此可能会在参数周围加上多余的括号,因为您知道如果在COM方法中进行了修改,将无法访问参数。但是,不幸的是,这种黑客不适用于PHP的COM库。

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.

您能做的最好的事情是我认为编写一个封装了COM的COM库。 LogicControlOEM 命名空间,但到处都接受变量参数。

The best you can do is I think writing a COM library that wraps the LogicControlOEM namespace but accepts variant parameters everywhere.

创建此类库最简单的环境当然是Visual Basic 6.0 。请注意,它仅是32位。

The easiest environment for creating such a library is Visual Basic 6.0 of course. Note that it's 32-bit only.

BTW自2005年末以来,没有对PHP COM进行任何重大维护。根据经验,我可以说 com_exception 错误消息在大多数情况下无法可靠地指向正确的参数位置。

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.

这篇关于PHP-使用COM错误消息:参数5:类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆