php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48498 COM object instantiation throws 'Invalid Syntax' exception
Submitted: 2009-06-08 18:05 UTC Modified: 2010-04-12 06:32 UTC
From: will at flourishlib dot com Assigned:
Status: Not a bug Package: COM related
PHP Version: 5.2.10RC1 OS: Windows XP SP3
Private report: No CVE-ID: None
 [2009-06-08 18:05 UTC] will at flourishlib dot com
Description:
------------
In previous versions of PHP it was possible to create a COM object for CAPICOM to generate random data. I'm not sure at what version it broke, but now trying to instantiate the COM object, an exception is thrown with the message "Failed to create COM object 'CAPICOM.Utilities.1': Invalid syntax".

This behavior seem to be present on both 5.2.9-2 and 5.2.10RC1.

I've been unable to figure out what this error really means. The ProgID I'm specifying is valid according to Microsoft - http://msdn.microsoft.com/en-us/library/aa388176(VS.85).aspx.

Any sort of direction would be useful in trying to solve this issue.

Reproduce code:
---------------
new COM('CAPICOM.Utilities.1');

Expected result:
----------------
A COM object that can be used.

Actual result:
--------------
An exception with the message:
Failed to create COM object 'CAPICOM.Utilities.1': Invalid syntax

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-27 00:11 UTC] paul at mantisforge dot org
This functionality seems to work fine in the 5.3.0 rc builds ( PHP 
5.3.0RC5-dev (cli) (built: Jun 27 2009 00:33:01) (DEBUG)).

The following script appears to work for me against most of the 
capicom.utilities functions: 

<?php 

try {
	$util = new COM('CAPICOM.Utilities.1');
} catch (Exception $e) {
	echo $e->getMessage() . "\n";
	echo 'exception initialising com object... terminating...';
}

$string = 'foo';

$encoded = $util->Base64Encode($string); /* encoded string is \r\n 
terminated */
echo $encoded . ' is base 64 encoded string:' . $util-
>Base64Decode($encoded) . "\n";
echo "\n\n";

$hex = $util->BinaryToHex($string);
echo "BinaryToHex: " . $util->BinaryToHex($string) . "\n";
echo "hextobinary: " . $util->HexToBinary($hex) . "\n";
define( 'CAPICOM_ENCODE_BASE64', 0 );

echo "Random Number: " . $util->GetRandom(10, CAPICOM_ENCODE_BASE64) . 
"\n";

$variant = $util->BinaryStringToByteArray($string);
$i = 0;
foreach( $variant as $v) {
 echo "Byte(" . $i++ . "): " . $v . "\n";
}


Outputing:
ZgBvAG8A
 is base 64 encoded string:foo

BinaryToHex: 66006F006F00
hextobinary: foo
Random Number: PiMSnPtckiHFCQ==

Byte(0): 102
Byte(1): 0
Byte(2): 111
Byte(3): 0
Byte(4): 111
Byte(5): 0

----------------------------------

1) It might be worth trying a newer version of php
2) it might be worth checking that the com object is registered 
correctly by attempting to access it from a vbscript
 [2009-11-03 21:29 UTC] ksingla@php.net
I was able to use CapiCom.Utilities.1 with PHP 5.2.11. Error is generated when capicom is not registered and class is not available on the machine.
 [2010-04-12 00:01 UTC] philip@php.net
-Status: Open +Status: Verified
 [2010-04-12 00:01 UTC] philip@php.net
Please let us know when Capicom is (or is not) available because I have a fresh XP 
install here, with a new PHP 5.3.2 install, and am also getting "Failed to create 
COM object 'CAPICOM.Utilities.1': Invalid syntax"
 [2010-04-12 01:30 UTC] kalle@php.net
-Status: Verified +Status: Bogus
 [2010-04-12 01:30 UTC] kalle@php.net
This is indeed because CAPICOM.Utilities.1 isn't installed.

What you need to do is to:
1) Install CAPICOM from: http://www.microsoft.com/downloads/details.aspx?FamilyId=860EE43A-A843-462F-ABB5-FF88EA5896F6&displaylang=en
2) Register the DLL: regsvr32 capicom.dll (capicom.dll is located in the installed folder in %ProgramFiles%)
 [2010-04-12 06:32 UTC] will at flourishlib dot com
Thanks for the replies/help on this. Is it possible to improve the error message 
so it says the COM object is "Not found" instead of "Invalid syntax"?

I understand if this is outside the control of PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 04:01:28 2024 UTC