php & com

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

php & com

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's your error log say?
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

Post 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
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

Post by alanchinese »

i found the solution, by using the regedit.exe and found the object name and class...
thankx.
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

Post by alanchinese »

further quetsion: how do you know what kind of methods and properties you can use inside that object class?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

whatever interfaces are exposed, you'll have to use QueryInterface() on the IUnknown's you receive..
Post Reply