PHP: COM support functions for Windows - Manual
PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previousccvs_voidCOMnext
Last updated: Tue, 16 Jul 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Hungarian | Italian | Japanese | Korean | Romanian | Russian | Spanish | Turkish

VIII. COM support functions for Windows

Wprowadzenie

COM is a technology which allows the reuse of code written in any language (by any language) using a standard calling convention and hiding behind APIs the implementation details such as what machine the Component is stored on and the executable which houses it. It can be thought of as a super Remote Procedure Call (RPC) mechanism with some basic object roots. It separates implementation from interface.

COM encourages versioning, separation of implementation from interface and hiding the implementation details such as executable location and the language it was written in.

COM functions are only available on the Windows version of PHP.

Predefiniowane sta�e

Poni�sze sta�e s� zdefiniowane w tym rozszerzeniu i staj� si� dost�pne, gdy rozszerzenie jest dokompilowane do PHP, lub za�adowane dynamicznie przy starcie.

CLSCTX_INPROC_SERVER (integer)

CLSCTX_INPROC_HANDLER (integer)

CLSCTX_LOCAL_SERVER (integer)

CLSCTX_REMOTE_SERVER (integer)

CLSCTX_SERVER (integer)

CLSCTX_ALL (integer)

VT_NULL (integer)

VT_EMPTY (integer)

VT_UI1 (integer)

VT_I2 (integer)

VT_I4 (integer)

VT_R4 (integer)

VT_R8 (integer)

VT_BOOL (integer)

VT_ERROR (integer)

VT_CY (integer)

VT_DATE (integer)

VT_BSTR (integer)

VT_DECIMAL (integer)

VT_UNKNOWN (integer)

VT_DISPATCH (integer)

VT_VARIANT (integer)

VT_I1 (integer)

VT_UI2 (integer)

VT_UI4 (integer)

VT_INT (integer)

VT_UINT (integer)

VT_ARRAY (integer)

VT_BYREF (integer)

CP_ACP (integer)

CP_MACCP (integer)

CP_OEMCP (integer)

CP_UTF7 (integer)

CP_UTF8 (integer)

CP_SYMBOL (integer)

CP_THREAD_ACP (integer)

Zobacz r�wnie�

For further information on COM read the or perhaps take a look at Don Box's

Spis tre�ci
COM -- COM class
VARIANT -- VARIANT class
com_addref --  Increases the components reference counter.
com_get --  Gets the value of a COM Component's property
com_invoke --  Calls a COM component's method.
com_isenum -- Grabs an IEnumVariant
com_load_typelib -- Loads a Typelib
com_load --  Creates a new reference to a COM component
com_propget --  Gets the value of a COM Component's property
com_propput --  Assigns a value to a COM component's property
com_propset --  Assigns a value to a COM component's property
com_release --  Decreases the components reference counter.
com_set --  Assigns a value to a COM component's property
User Contributed Notes
COM support functions for Windows
add a note about notes

20-Dec-2000 06:45

As Jason ([email protected]) as demonstrated in his code example, there is a
PHP database wrapper class library that can connect to ADO available
called ADODB. 

It is available from  and
supports many databases both on Windows and Linux.

Modelled after ADO, so it should be easy for Windows programmers to learn.


31-Mar-2001 11:37

I thought i'd share with those of you unfamiliar with one of the cool
things
about developing php on win32 systems..



This is a good article, but i don't think the author hit the nail on the
head showing how useful this can be.

Now, checkout this article:


Notice how he describes 1) how to build a com object & 2) how to call
and
use the com object from ASP.

In php, this is how you would call the same object:

<?
$instance = new COM("Checkyear.LeapYear");
$isleapyear = $instance->IsLeapYear($year);
$instance->close();
if($isleapyear) {
echo "The <b>$year</b> is a leap year";
}
else {
echo "The <b>$year</b> is not a leap year";
}
?>

I hope this helps someone.. you can contact me at [email protected] if
you would like to discuss this further.


28-Feb-2002 03:11

now in PHP >=4.0.6
programming in window can use the
ADO through the COM like this:
$dbconn=new COM ("ADODB.Connection") or die ("connection
create fail");
 $dbconn->Open("Provider=sqloledb;Data Source=ndht;Initial
Catalog=printers;User Id=printers;Password=printers;");
 $rec=new COM("ADODB.Recordset") or die ("create Recordset
error");
 while (!$rec->EOF)
 {
echo $rec->fields["fieldname"]->value."
"; $rec->movenext(); } $rec->close(); $dbconn->close(); but there's still a little question of working with the image field of mssql server.


07-Mar-2002 06:59

I thought this excel chart example could be useful.

Note the use of Excel.application vs Excel.sheet.

<pre>
<?php
    print "Hi";
#Instantiate the spreadsheet component.
#    $ex = new COM("Excel.sheet") or Die ("Did not
connect");
$exapp = new COM("Excel.application") or Die ("Did not
connect");

#Get the application name and version    
print "Application name:{$ex->Application->value}
" ; print "Loaded version: {$ex->Application->version}
"; $wkb=$exapp->Workbooks->add(); #$wkb = $ex->Application->ActiveWorkbook or Die ("Did not open workbook"); print "we opened workbook
"; $ex->Application->Visible = 1; #Make Excel visible. print "we made excell visible
"; $sheets = $wkb->Worksheets(1); #Select the sheet print "selected a sheet
"; $sheets->activate; #Activate it print "activated sheet
"; #This is a new sheet $sheets2 = $wkb->Worksheets->add(); #Add a sheet print "added a new sheet
"; $sheets2->activate; #Activate it print "activated sheet
"; $sheets2->name="Report Second page"; $sheets->name="Report First page"; print "We set a name to the sheet: $sheets->name
"; # fills a columns $maxi=20; for ($i=1;$i<$maxi;$i++) { $cell = $sheets->Cells($i,5) ; #Select the cell (Row Column number) $cell->activate; #Activate the cell $cell->value = $i*$i; #Change it to 15000 } $ch = $sheets->chartobjects->add(50, 40, 400, 100); # make a chartobject $chartje = $ch->chart; # place a chart in the chart object $chartje->activate; #activate chartobject $chartje->ChartType=63; $selected = $sheets->range("E1:E$maxi"); # set the data the chart uses $chartje->setsourcedata($selected); # set the data the chart uses print "set the data the chart uses
"; $file_name="D:/apache/Apache/htdocs/alm/tmp/final14.xls"; if (file_exists($file_name)) {unlink($file_name);} #$ex->Application->ActiveWorkbook->SaveAs($file_name); # saves sheet as final.xls $wkb->SaveAs($file_name); # saves sheet as final.xls print "saved
"; #$ex->Application->ActiveWorkbook->Close("False"); $exapp->Quit(); unset($exapp); ?> </pre> Alex Madon


02-Apr-2002 10:01

An easy way to send e-mail using your default Outlook account:
<?
$objApp = new COM("Outlook.Application");
$myItem = $objApp->CreateItem(olMailItem);
$a=$myItem->Recipients->Add("[email protected]");
$myItem->Subject="Subject";
$myItem->Body="This is a Body Section now.....!";
$myItem->Display();
$myItem->Send();
?>


19-Apr-2002 10:34

an easy way to convert your file from .doc to .html

// starting word
$word = new COM("word.application") or die("Unable to
instanciate Word");

// if you want see thw World interface the value must be '1' else '0'
$word->Visible = 1;

//doc file location
$word->Documents->Open("E:\\first.doc");

//html file location  '8' mean HTML format
$word->Documents[1]->SaveAs("E:\\test_doc.html",8);

//closing word
$word->Quit();

//free the object from the memory
$word->Release();
$word = null;


03-Jun-2002 05:31

Hi, I'm Frank, i have problem with function COM, the sentence that I use
is...
$app=new COM("word.application");

return a error that is...
Warning: Unable to obtain IDispatch interface for CLSID
{000209FF-0000-0000-C000-000000000046}: Se ha denegado el acceso. 

I need help...
in the file PHP.INI have...
com.allow_dcom = true


03-Jun-2002 05:41

Hi... I'm Frank (chile)
I have installing the PHP 4.2.1 and I have the next problem, at utilized
the library php_oci8.dll return the next error...

PHP Warning: Unable to load dynamic library
'C:\php\extensions/php_oci8.dll' - No se ha encontrado el proceso
especificado

I has update the file php_oci8.dll, but equality return the error.

before I have the php 4.0.4  and I not have the problem... also with the
new version give me problem with the function COM()


18-Jun-2002 05:17

reinstall the previous php version...


28-Jun-2002 04:48

Complementing Alex's Excell Example, let's print the SpreadSheet to a PDF
file using Acrobat Distiller:

$null = new VARIANT("null", VT_NULL);

$wkb->PrintOut($null->value, $null->value, $null->value,
$null->value, "Acrobat Distiller");

There you go!!!


09-Jul-2002 05:44

Apparently you can only use COM objects which have the Count and Item
methods.

sangapum at hotmail
18-Jul-2002 03:50

MS Outlook & PHP

This was posted by someone, earlier on in the page:
=============================
An easy way to send e-mail using your default Outlook account:
<?
$objApp = new COM("Outlook.Application");
$myItem = $objApp->CreateItem(olMailItem);
$a=$myItem->Recipients->Add("[email protected]");
$myItem->Subject="Subject";
$myItem->Body="This is a Body Section now.....!";
$myItem->Display();
$myItem->Send();
?>
==========================

I'm running Win NT 4, latest version of PHP on my Apache server (latest
ver.)

I'm not able to get this to work. I tried opening up a word application
and it worked flawlessly (thru a different example on the page).

But outlook is having problems. Although the first two lines "$objApp
= new COM("Outlook.Application"); $myItem =
$objApp->CreateItem(olMailItem);" seem to work okay because it is
able to return a version number when I echo it. But anything after that
has trouble. I'm running outlook ver 9.

Has anyone else run into any similar situations? My goal is to open
outlook to access some email-groups and send out a customized email.
Basically I need to grab those email addresses in the groups
(distribution-lists).

Help!

add a note about notes
previousccvs_voidCOMnext
Last updated: Tue, 16 Jul 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Fri Jul 26 12:06:26 2002 CEST