Page 1 of 1

php & com

Posted: Fri Jun 11, 2004 4:53 pm
by alanchinese
hi, i saw some examples on how to use COM objects by PHP 4. but they are all about Excel, Word, ADODB etc.
if i have a library named "mylibrary.dll", how do you make php know the existence of the libray, and how do you know what functions this library provide you, and how do you load the library in the php program?
it dies when i tried to run this program.

<?php
// create an object instance
$mylibrary = new COM("C:\lib\MyLibrary.dll") or die("MyLibrary could not be started");
$mylibrary = null;
?>


1. I have built a DLL to calculate something. Is there any way to run this DLL under PHP ?

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.

what does the above faq mean? i can't use MyLibrary.dll? how do you know if this particular dll implement the IDispatch interface?

Posted: Fri Jun 11, 2004 5:22 pm
by feyd
A correctly installed COM server will be registered with the system. Calling CoCreateInstance() with the proper GUID will load the DLL and initialize the COM parts associated.

If your dll doesn't implement the COM system components, use win32api

Posted: Fri Jun 11, 2004 5:40 pm
by alanchinese
the MyLibrary.dll is working well with the C#.NET interoperability.
i have done the followin:
1) used regsvr32 on MyLibrary.dll
2) found out the dll has 3 class, named ClassA, ClassB, ClassC (from the visual studio.net 2003 object browser)
3) changed the php.ini file to the following:
[com]
; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
;com.typelib_file =
; allow Distributed-COM calls
com.allow_dcom = true
; autoregister constants of a components typlib on com_load()
com.autoregister_typelib = true
; register constants casesensitive
com.autoregister_casesensitive = false
; show warnings on duplicate constat registrations
com.autoregister_verbose = true
4) restart aparche
5) make a little php program.
<?php
$myobj = new COM("MyLibrary.ClassA") or die("dead here");
$myobj = null;
?>

it still dies, what's going on?
(minor question: do i need to load all the classes from that dll?)
thankx a lot.

Posted: Fri Jun 11, 2004 5:44 pm
by feyd
what's your error log say?

Posted: Fri Jun 11, 2004 6:44 pm
by alanchinese
oh i fianlly found it:
[client 1.2.3.4.5] PHP Warning: (null)(): Invalid ProgID, GUID string, or Moniker: Invalid syntax\r\n in C:\\test.php on line 5

Posted: Fri Jun 11, 2004 7:51 pm
by alanchinese
i found the solution, by using the regedit.exe and found the object name and class...
thankx.

Posted: Fri Jun 11, 2004 7:52 pm
by alanchinese
further quetsion: how do you know what kind of methods and properties you can use inside that object class?

Posted: Fri Jun 11, 2004 8:14 pm
by feyd
whatever interfaces are exposed, you'll have to use QueryInterface() on the IUnknown's you receive..