Search code examples
.netwindowscomphp

PHP5 COM(), DOTNET(): how to start?


Where I'm stuck is the right parameter syntax to instantiate an object using PHP's com() and dotnet() classes to load .net assemblies, windows system applications and components beyond the usual MS Office apps. If successfully created, working with the objects isn't an issue here.

Can anyone explain what each part of each parameter means for both classes, and how I can find out the proper calling syntax for any application, component or assembly? What exactly can or can't PHP load, and if it can, how? How do I go about finding out which system components and classes are visible and can be made available through com() and dotnet()? For calling assemblies, Im I incorrect in assuming anything listed in /windows/assembly/gacxx folders can be used here?

I'm trying to dig deeper into connecting to or using Windows system applications, components and assemblies. For example, using 'System.Windows.Forms' assembly. After reviewing PHP's manual on the topic including code examples, it's not getting any clearer for me. By PHP's errors, I'm failing to get the syntax right, failing to find the specified files, or otherwise just failing completely without explanation. No related events are showing in Event Viewer to hint at application crashing or denied access.

I have .net 4 framework installed. These are my current PHP settings...

compiled: --enable-com-dotnet

[com_dotnet]

  • COM support => enabled
  • DCOM support => disabled
  • .Net support => enabled

Directive => Local Value => Master Value

  • com.allow_dcom => 0 => 0
  • com.autoregister_casesensitive => no value => no value
  • com.autoregister_typelib => 1 => 1
  • com.autoregister_verbose => 1 => 1
  • com.code_page => no value => no value
  • com.typelib_file => no value => no value

I've managed to get just three cases working so far. All other cases fail, including attempting to use other mscorlib classes...

<?php

$scripting = new COM("MSScriptControl.ScriptControl");
$scriping_host = new COM("WScript.Shell');
$stack = new DOTNET("mscorlib", "System.Collections.Stack");

?>

I see 'System.Windows.Forms' just sitting there in the /windows/assembly folder taunting me. $forms = new DOTNET('System.Windows.Forms', 'Form'); fails, even if the full assembly string is used. Am I looking in the wrong place? Should I instead approach this from within .net and create my own assembly to allow me to dynamically call others from PHP?

Note: Using the win32api PHP extension instead is right out as it's a dead project, and I'm hoping to step away from being dependent on others' pet project extensions.

Edit: COM issue mostly solved. Within the registry, I was able to find a list of com supported software and system components and create several com objects using their clsid's. Still unsure exactly how to create DOTNET objects though.


Solution

  • Try this:

    $forms = new DOTNET('System.Windows.Forms', 'System.Windows.Forms.Form');
    

    I notice that the examples from the manual use fully-qualified class names.