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.
PHP 和 COM
PHP 可以在 Win32 平台中访问 COM 和 DCOM 对象。
- æå»ºç«äºä¸ä¸ª DLL æ¥åæç§è®¡ç®ãæåæ³å¨ PHP ä¸è¿è¡è¿ä¸ª DLL åï¼
- âUnsupported variant type: xxxx (0xxxxx)âæ¯ä»ä¹ææï¼
- å¨ PHP 䏿å¯è½æçºµå¯è§å¯¹è±¡åï¼
- å¯ä»¥å°ä¸ä¸ª COM 对象ä¿åå¨ session ä¸åï¼
- ææ ·å¯ä»¥æè· COM çé误ï¼
- æè½åå¨ Perl ä¸ä¸æ ·ä» PHP èæ¬çæ DLL æä»¶åï¼
- âUnable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}âæ¯ä»ä¹ææï¼
- ææ ·ä»è¿ç«¯æå¡å¨è¿è¡ COM 对象ï¼
- æå¾å°ä¸ä¸ªâDCOM is disabled in C:\path...\scriptname.php on line 6âä¿¡æ¯ï¼åºè¯¥æä¹åï¼
- æå¯è½å¨ PHP 页é¢ä¸å è½½ï¼æçºµ ActiveX 对象åï¼
- æå¯è½å¾å°ä¸ä¸ªç»ä»¶å¨è¿è¡ä¸çå®ä¾åï¼
- æåæ³å¤ç COM 对象ä¸åéçäºä»¶åï¼
- æå¨å°è¯è°ç¨ä¸ä¸ªæå¼äºå¤äºä¸ä¸ªæ¥å£ç COM 对象ä¸çæ¹æ³æ¶ç¢°å°é®é¢ï¼åºè¯¥æä¹åï¼
- è¿ä¹è¯´ PHP å¯ä»¥å COM ä¸èµ·å·¥ä½ï¼é£ä¹ COM+ å¢ï¼
- 妿 PHP å¯ä»¥æçºµ COM 对象ï¼é£ä¹å¯ä»¥è®¾æ³ç»å PHP ç¨ MTS æ¥ç®¡çç»ä»¶èµæºåï¼
-
我建立了一个 DLL 来做某种计算。有办法在 PHP 中运行这个 DLL 吗?
-
如果这是个简单的 DLL 那么还没有办法在 PHP 中运行它。如果这个 DLL 中包含有一个 COM 服务器并且它实现了 IDispatch 接口,那有可能访问它。
-
“Unsupported variant type: xxxx (0xxxxx)”是什么意思?
-
有几十种 VARIANT 类型以及它们的组合。大多数已经被支持了但还有几种尚未实现。数组没有完全被支持。只有一维的仅用作索引的数组可以在 PHP 和 COM 之间传递。如果你发现其它未支持的类型,请当作一个 bug 报告(如果尚未被报告的话)并提供尽可能多的信息。
-
在 PHP 中有可能操纵可视对象吗?
-
一般来说是可以的,但是 PHP 大都用来作为 web 脚本语言并运行在 web 服务器的上下文环境中,因此可视对象决不会在服务器的桌面上显示。如果你把 PHP 用作应用程序脚本例如结合 PHP-GTK 来使用,那么访问和通过 COM 来操纵可视对象方面没有限制。
-
怎样可以捕获 COM 的错误?
-
在 PHP 5 中,COM 扩展会发出 com_exception 异常信息,可以捕获并检查 code 成员来决定下一步的行为。
在 PHP 4 中除了用 PHP 自己提供的办法之外(@,track_errors,..)不可能捕获 COM 的错误。
-
“Unable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}”是什么意思?
-
此错误可以有多种原因:
- 错误的 CLSID
- 找不到所请求的 DLL
- 所请求的组件没有实现 IDispatch 接口
-
怎样从远端服务器运行 COM 对象?
-
完全和运行本地对象一样。只须将远端服务器的 IP 作为第二个变量传递给 COM 的构造函数即可。
确认在 php.ini 中设定了 COM=TRUE。
-
我得到一个“DCOM is disabled in C:\path...\scriptname.php on line 6”信息,应该怎么办?
-
编辑 php.ini 并设定 COM=TRUE。
-
有可能在 PHP 页面中加载/操纵 ActiveX 对象吗?
-
这不关 PHP 的事。如果在 HTML 文档中请求的话,ActiveX 对象被加载在客户端。这和 PHP 脚本没有关系,因此也不可能和服务器端发生直接的交互作用。
-
有可能得到一个组件在运行中的实例吗?
-
在绰号的帮助下这有可能。如果你想得到同一个 word 实例的多个引用你可以这样建立此实例:
<?php
$word = new COM("C:\docs\word.doc");
?>如果没有运行中的实例这将建立一个新的实例,否则将会返回正在运行中的实例的句柄,如果可用的话。
-
有办法处理 COM 对象中发送的事件吗?
-
可以自定义事件收报方并且用 com_event_sink() 函数绑定之。可以用 com_print_typeinfo() 来让 PHP 产生事件收报方类的框架。
-
我在尝试调用一个打开了多于一个接口的 COM 对象中的方法时碰到问题,应该怎么办?
-
我也不知道怎么办,我想这没办法。如果什么人有对此问题的明确信息请» 告诉我。:)
PHP 和 COM
27-Jan-2007 09:18
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.
03-Feb-2005 10:56
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
06-Oct-2004 12:27
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.
17-Aug-2002 12:39
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;
?>
