PHP 可以在 Win32 平台中访问 COM 和 DCOM 对象。
如果这是个简单的 DLL 那么还没有办法在 PHP 中运行它。如果这个 DLL 中包含有一个 COM 服务器并且它实现了 IDispatch 接口,那有可能访问它。
有几十种 VARIANT 类型以及它们的组合。大多数已经被支持了但还有几种尚未实现。数组没有完全被支持。只有一维的仅用作索引的数组可以在 PHP 和 COM 之间传递。如果你发现其它未支持的类型,请当作一个 bug 报告(如果尚未被报告的话)并提供尽可能多的信息。
一般来说是可以的,但是 PHP 大都用来作为 web 脚本语言并运行在 web 服务器的上下文环境中,因此可视对象决不会在服务器的桌面上显示。如果你把 PHP 用作应用程序脚本例如结合 PHP-GTK 来使用,那么访问和通过 COM 来操纵可视对象方面没有限制。
不行。COM 的实例被看作是资源,因此只在一个脚本的上下文中有效。
在 PHP 5 中,COM 扩展会发出 com_exception异常信息,可以捕获并检查 code成员来决定下一步的行为。
在 PHP 4 中除了用 PHP 自己提供的办法之外(@,track_errors,..)不可能捕获 COM 的错误。
不行,PHP 没有这样的工具。
此错误可以有多种原因:
这不关 PHP 的事。如果在 HTML 文档中请求的话,ActiveX 对象被加载在客户端。这和 PHP 脚本没有关系,因此也不可能和服务器端发生直接的交互作用。
在绰号的帮助下这有可能。如果你想得到同一个 word 实例的多个引用你可以这样建立此实例:
<?php
$word = new COM("C:\docs\word.doc");
?>
如果没有运行中的实例这将建立一个新的实例,否则将会返回正在运行中的实例的句柄,如果可用的话。
可以自定义事件收报方并且用 com_event_sink()函数绑定之。可以用 com_print_typeinfo()来让 PHP 产生事件收报方类的框架。
我也不知道怎么办,我想这没办法。如果什么人有对此问题的明确信息请 » 告诉我。:)
COM+ 通过使用 MTS 和 MSMQ 来管理组件的框架扩展了 COM,但并没有什么特殊之处使 PHP 非要支持这样的组件。
PHP 本身还并不处理事务。因而如果出错也不会发动撤回机制。如果你使用了支持事务处理的组件那你不得不自己实现事务管理。
microtrash at at gmail dot com (2008-07-09 11:29:52)
In reference to question 1:
On one project I had a dll that exposed certain functions I wished to call from within PHP. I created a PHP Module which had a matching function for each in the DLL. The PHP Module did no processing, merely served as an adapter for the original DLL.
codeslinger at compsalot dot com (2007-01-27 05:18:59)
in response to item #1 above: "If this is a simple DLL there is no way yet to run it from PHP."
Answer: There are several different packages/add-ons to php that enable low level access to the windows api. One of the most popular of these packages is available at http://www.winbinder.org
Winbinder does have the ability to load a dll and call it's functions. Winbinder also provides a large set of windows apis for creating windows and controls. This is useful for creating stand-alone desktop apps. It is a possible alternative to php-gtk.
I've had mixed results with Winbinder, some things work very well, others are buggy; source code is available. It's worth a look, Evaluate carefully.
(2005-07-17 04:56:41)
Re: The Windows English CHM Sample with MS Word Automation.
I see that $Word->Release() is called after $Word->Quit().
This seems to be erroneous. Actually, $Word->Release() should not have to be called if proper COM garbage collection is taking place. Release() is a C++ construction not used in either Visual Basic or VBScript or even MS-JScript. Just to be sure, however, I ran the sample through php.exe (5.04 CLI on Windows XP SP1 with Office 2003) and got a RPC failed error on the line containing $Word->Release(). The rest of the sample works fine, and the results are as expected. So, I propose 2 scenarios:
1.There is a problem with the documentation (more likely).
2.There is a problem with PHP504 itself, as this problem is reproduced with any COM Automation call, not just Word.
jeanpierre dot vincent at gmail dot com (2005-02-03 06:56:13)
Be careful with function com_event_sink(), it doesn't totally work : when catching events, all parameters given to your callback function have the same value as the last one => see bug http://bugs.php.net/bug.php?id=31040
junk.ghost@virgin dOtt net (2004-10-05 09:27:23)
It may be obvious to everyone else but...
If you want to write your own COM DLL in MSVC++6 and you want to pass it a string, you need the following in your .idl file:
HRESULT function_name([in] BSTR parameter_name,
[retval, out] BSTR * retval);
retval is the result of your function as a string to be passed back.
BSTR is an unsigned short *, so if you want to use your string with STL string etc. you may need to convert parameters to and from char *.
The burden of my message is that from PHP
$comThing = new COM("comThing.comThing");
print $comThing->function_name("Jeremy");
Jeremy will be marshalled as wide chars, which match BSTR.
ALAN at DONTSPAMMEE;HOGAR dot COM (2002-08-16 21:39:43)
ONE SAMPLE USING MS-XML3 PARSER ON WINDOWS
<?
$xml= new COM("Microsoft.XMLDOM");
$xml->async=false;
$xml->load("STYLE.xml");
$xsl = new COM("Microsoft.XMLDOM");
$xsl->async=false;
$xsl->load("STYLE.xsl");
$response=$xml->transformNode($xsl);
print $response;
?>