Instantiating an object

PHP handles COM objects as native PHP objects, meaning that you can read and write variables, and also call functions, just like you would on any other object. The COM object class is simple "COM", and you need to pass it the name of COM component to create as the parameter to its constructor.

To find out the names of the COM components you have installed (you almost certainly have hundreds), click Start, then Run, then enter "regedit" and click OK. From the three on the left, open up HKEY_CLASSES_ROOT, and you will see a long list of file extensions, probably ending around ".zip". After that, you will see a big long list of the names of COM components - just pick one from there, and you are all set.


Note that COM scripts should generally be run from the command line. Running them through a web server is possible, but COM objects that interact with the user on the server need to have special permissions granted to them. This can usually be accomplished using the Services administrative tool, but this may be different on your version of Windows.

Just below is a screenshot of how to enable Apache to launch visible desktop applications that can be interacted with:


It is important to note that starting a complicated COM object for the first time will be quite slow, but a lot of the information is cached by Windows for several minutes after the object is freed, so subsequent start ups will be much faster. If you find a script is executing slowly, try it out a few times to see whether it is just the initial start up time that is slow.

 

Next chapter: Basic COM >>

Previous chapter: Getting started with COM

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar