简体   繁体   English

PHP、COM对象,出参数

[英]PHP, COM objects, and out parameters

I'm using PHP to work with a COM object and one of the COM object's function's parameters is an "out" parameter.我正在使用 PHP 与 COM object 一起使用,其中一个 ZD47C174ED277BDF06CFC72763AB7 函数参数是“706CFC72763AB7”参数。 How does PHP work with these? PHP 如何与这些一起工作?

Example (ModifyParam could do anything, like output the word of the day or provide an object):示例(ModifyParam 可以做任何事情,例如 output 当天的词或提供对象):

$MyCom = new COM("APPLib.APP");

$outParam;
//APP.ModifyParam(out object pParam)
$MyCom->ModifyParam($outParam);

var_dump($outParam); //NULL

The example is based on actual code which outputs what would be an object array, or an array of strings.该示例基于输出 object 数组或字符串数组的实际代码。 The real code isn't outputting the list though.真正的代码并没有输出列表。

As far as I know (you can correct me if I'm wrong here) - the [out] parameter means the variable to store the results.据我所知(如果我在这里错了,你可以纠正我) - [out]参数表示存储结果的变量。 So if you have this method in the COM object:所以如果你在COM object中有这个方法:

GetUserInfo([in] long machineID, [out] long* userID, [out] BSTR* userName)

The [in] parameter means the argument, the [out] parameter are result variables that will get written, much like how MySQLi::bind_result() method works. [in]参数表示参数, [out]参数是将被写入的结果变量,就像MySQLi::bind_result()方法的工作方式一样。 Example code to use the method above (assuming the COM object has been set appropriately):使用上述方法的示例代码(假设 COM object 已正确设置):

$obj = new COM('Namespace.Class');

// This is the [in] parameter, the machine number we wanted to inspect.
$machineID = 1

// Define [out] variables with the correct type, according to the API.
$userID = 0;
$userName = '';

// Call the COM method.
$obj->GetUserInfo($machineID, $userID, $userName);

// Print the results.
echo "User ID: $userID<br />";
echo "User Name: $userName";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM