[php-src] Issue #8750: php_com_dotnet - can not create VT_ERROR variant type
| From: | systoolz | Date: | Fri, 10 Jun 2022 18:32:49 +0000 |
| Subject: | [php-src] Issue #8750: php_com_dotnet - can not create VT_ERROR variant type | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241712@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8750
Author: systoolz
### Description
Can not create VT_ERROR variant type. It's required for some COM method calls where you need to
specify an empty argument, since it's VT_ERROR type variant with error DISP_E_PARAMNOTFOUND
(0x80020004) as actual error code ([see
here](https://devblogs.microsoft.com/oldnewthing/20140129-00/?p=1933)).
The following code:
```php
<?php // database.php
// next line works only in PHP 4.4.9 (PHP 5, 6, 7 and 8 are bugged)
$vtMissing = new VARIANT(0x80020004, VT_ERROR);
$db = new COM('ADODB.Connection');
$db->ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb';
$db->Mode = 1; // adModeRead
$db->Open();
// adSchemaProviderSpecific, *missing*, JET_SCHEMA_USERROSTER
$rs = $db->OpenSchema(-1, $vtMissing, '{947bb102-5d43-11d1-bdbf-00c04fb92675}');
// manual counting since rs.RecordCount is -1 (not supported)
$i = 0;
while (!$rs->EOF) {
$rs->MoveNext();
$i++;
}
$rs->Close();
$rs = null;
$db->Close();
$db = null;
echo $i;
```
Resulted in this output:
```
Fatal error: Uncaught com_exception: Variant type conversion failed: Type mismatch in
Z:\database.php:3
Stack trace:
#0 Z:\database.php(3): variant->__construct(2147614724, 10)
#1 {main}
thrown in Z:\database.php on line 3
```
But I expected this output instead:
```
1
```
Test file "database.mdb" can be any Microsoft Access database file, even without any
tables inside.
More details can be found in this article (auto-translated from Russian):
[VT_MISSING argument in PHP for COM
objects](https://systools-losthost-org.translate.goog/?articles=8&_x_tr_sl=ru&_x_tr_tl=en&_x_tr_hl=en-US&_x_tr_pto=wapp)
### PHP Version
PHP 8.1.7 x64
### Operating System
Windows 7 x64