2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 05:34:55 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<chapter xml:id="faq.com" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
2001-10-03 16:00:12 +00:00
|
|
|
<title>PHP and COM</title>
|
|
|
|
<titleabbrev>PHP and COM</titleabbrev>
|
|
|
|
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
PHP can be used to access COM and DCOM objects on Win32 platforms.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<qandaset>
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q1">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
I have built a DLL to calculate something. Is there any way to run this DLL under PHP ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
If this is a simple DLL there is no way yet to run it from PHP. If the DLL contains a COM
|
|
|
|
server you may be able to access it if it implements the IDispatch interface.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q2">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
What does 'Unsupported variant type: xxxx (0xxxxx)' mean ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
There are dozens of VARIANT types and combinations of them. Most of them are already supported but
|
|
|
|
a few still have to be implemented.
|
|
|
|
Arrays are not completely supported. Only single dimensional indexed
|
|
|
|
only arrays can be passed between PHP and COM.
|
|
|
|
If you find other types that aren't supported, please report them as a bug (if not already reported)
|
|
|
|
and provide as much information as available.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q3">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
Is it possible manipulate visual objects in PHP ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
Generally it is, but as PHP is mostly used as a web scripting language it runs in the web servers context, thus
|
|
|
|
visual objects will never appear on the servers desktop.
|
|
|
|
If you use PHP for application scripting e.g. in conjunction with PHP-GTK there is no limitation in accessing and
|
|
|
|
manipulating visual objects through COM.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q4">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
Can I store a COM object in a session ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
No, you can't. COM instances are treated as resources and therefore they are only available in a single script's context.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q5">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
How can I trap COM errors ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2004-05-03 15:04:52 +00:00
|
|
|
In PHP 5, the COM extension throws <literal>com_exception</literal>
|
|
|
|
exceptions, which you can catch and then inspect the <literal>code</literal>
|
|
|
|
member to determine what to do next.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
In PHP 4 it's not possible to trap COM errors beside the ways provided by PHP itself (@, track_errors, ..).
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q6">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
2010-09-09 04:38:34 +00:00
|
|
|
Can I generate DLL files from PHP scripts like I can in Perl ?
|
2002-04-29 12:05:52 +00:00
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2002-03-28 16:06:33 +00:00
|
|
|
No, unfortunately there is no such tool available for PHP.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q7">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
What does 'Unable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' mean ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
This error can have multiple reasons:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
2002-04-29 12:05:52 +00:00
|
|
|
<simpara>
|
2001-11-01 20:27:47 +00:00
|
|
|
the CLSID is wrong
|
2002-04-29 12:05:52 +00:00
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-11-01 20:27:47 +00:00
|
|
|
<listitem>
|
2002-04-29 12:05:52 +00:00
|
|
|
<simpara>
|
2001-11-01 20:27:47 +00:00
|
|
|
the requested DLL is missing
|
2002-04-29 12:05:52 +00:00
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-11-01 20:27:47 +00:00
|
|
|
<listitem>
|
2002-04-29 12:05:52 +00:00
|
|
|
<simpara>
|
2001-11-01 20:27:47 +00:00
|
|
|
the requested component doesn't implement the IDispatch interface
|
2002-04-29 12:05:52 +00:00
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q8">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
How can I run COM object from remote server ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2002-03-28 16:06:33 +00:00
|
|
|
Exactly like you run local objects. You only have to pass the IP of the remote machine as second parameter to
|
2001-11-01 20:27:47 +00:00
|
|
|
the COM constructor.
|
|
|
|
</para>
|
|
|
|
<para>
|
2009-01-03 10:01:04 +00:00
|
|
|
Make sure that you have set
|
|
|
|
<link linkend="ini.com.allow-dcom">com.allow_dcom</link><literal>=</literal>&true;
|
|
|
|
in your &php.ini;.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q9">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
I get 'DCOM is disabled in C:\path...\scriptname.php on line 6', what can I do ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2009-01-03 10:01:04 +00:00
|
|
|
Edit your &php.ini; and set
|
|
|
|
<link linkend="ini.com.allow-dcom">com.allow_dcom</link><literal>=</literal>&true;.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q10">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
Is it possible to load/manipulate an ActiveX object in a page with PHP ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
This has nothing to do with PHP. ActiveX objects are loaded on client side if they are requested
|
|
|
|
by the HTML document. There is no relation to the PHP script and therefore there is no direct
|
|
|
|
server side interaction possible.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q11">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
Is it possible to get a running instance of a component ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
This is possible with the help of monikers. If you want to get multiple references to the same word instance
|
|
|
|
you can create that instance like shown:
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
2001-11-09 15:48:16 +00:00
|
|
|
<programlisting role="php">
|
2004-03-21 16:53:09 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$word = new COM("C:\docs\word.doc");
|
|
|
|
?>
|
|
|
|
]]>
|
2001-11-01 20:27:47 +00:00
|
|
|
</programlisting>
|
2001-10-03 16:00:12 +00:00
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
This will create a new instance if there is no running instance available or it will return a handle to the
|
|
|
|
running instance, if available.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q12">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
Is there a way to handle an event sent from COM object ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2004-05-03 15:04:52 +00:00
|
|
|
You can define an event sink and bind it using
|
|
|
|
<function>com_event_sink</function>. You can use
|
|
|
|
<function>com_print_typeinfo</function> to have PHP generate a skeleton
|
|
|
|
for the event sink class.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q13">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
I'm having problems when trying to invoke a method of a COM object
|
|
|
|
which exposes more than one interface. What can I do ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
The answer is as simple as unsatisfying. I don't know exactly but i think you can do nothing.
|
2007-06-20 22:25:43 +00:00
|
|
|
If someone has specific information about this, please let <link xlink:href="mailto:&email.harald;">me</link> know :)
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q14">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
So PHP works with COM, how about COM+ ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-11-01 20:27:47 +00:00
|
|
|
COM+ extends COM by a framework for managing components through MTS and MSMQ but there is nothing special that
|
|
|
|
PHP has to support to use such components.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<qandaentry xml:id="faq.com.q15">
|
2001-10-03 16:00:12 +00:00
|
|
|
<question>
|
2002-04-29 12:05:52 +00:00
|
|
|
<para>
|
|
|
|
If PHP can manipulate COM objects, can we imagine to use
|
|
|
|
MTS to manage components resources, in conjunction with PHP ?
|
|
|
|
</para>
|
2001-10-03 16:00:12 +00:00
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2002-04-29 12:05:52 +00:00
|
|
|
PHP itself doesn't handle transactions yet. Thus if an error
|
|
|
|
occurs no rollback is initiated. If you use components that
|
|
|
|
support transactions you will have to implement the
|
|
|
|
transaction management yourself.
|
2001-10-03 16:00:12 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
2001-11-01 20:27:47 +00:00
|
|
|
|
2001-10-03 16:00:12 +00:00
|
|
|
</qandaset>
|
|
|
|
</chapter>
|
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
2001-12-12 20:47:43 +00:00
|
|
|
indent-tabs-mode:nil
|
2001-10-03 16:00:12 +00:00
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2001-10-03 16:00:12 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|