1
1
/*
2
2
+----------------------------------------------------------------------+
3
- | PHP Version 4 |
3
+ | PHP Version 5 |
4
4
+----------------------------------------------------------------------+
5
5
| Copyright (c) 1997-2003 The PHP Group |
6
6
+----------------------------------------------------------------------+
@@ -64,7 +64,7 @@ PHP_FUNCTION(com_create_instance)
64
64
& module_name , & module_name_len , & server_params , & obj -> code_page ,
65
65
& typelib_name , & typelib_name_len )) {
66
66
67
- php_com_throw_exception ("Could not create COM object - invalid arguments!" TSRMLS_CC );
67
+ php_com_throw_exception (E_INVALIDARG , "Could not create COM object - invalid arguments!" TSRMLS_CC );
68
68
ZVAL_NULL (object );
69
69
return ;
70
70
}
@@ -113,7 +113,7 @@ PHP_FUNCTION(com_create_instance)
113
113
}
114
114
115
115
if (server_name && !COMG (allow_dcom )) {
116
- php_com_throw_exception ("DCOM has been disabled by your administrator [com.allow_dcom=0]" TSRMLS_CC );
116
+ php_com_throw_exception (E_ERROR , "DCOM has been disabled by your administrator [com.allow_dcom=0]" TSRMLS_CC );
117
117
return ;
118
118
}
119
119
@@ -227,7 +227,7 @@ PHP_FUNCTION(com_create_instance)
227
227
spprintf (& msg , 0 , "Failed to create COM object `%s': %s" , module_name , werr );
228
228
LocalFree (werr );
229
229
230
- php_com_throw_exception (msg TSRMLS_CC );
230
+ php_com_throw_exception (res , msg TSRMLS_CC );
231
231
efree (msg );
232
232
ZVAL_NULL (object );
233
233
return ;
@@ -240,7 +240,7 @@ PHP_FUNCTION(com_create_instance)
240
240
/* load up the library from the named file */
241
241
int cached ;
242
242
243
- TL = php_com_load_typelib_via_cache (typelib_name , mode , obj -> code_page , & cached TSRMLS_CC );
243
+ TL = php_com_load_typelib_via_cache (typelib_name , obj -> code_page , & cached TSRMLS_CC );
244
244
245
245
if (TL ) {
246
246
if (COMG (autoreg_on ) && !cached ) {
@@ -341,7 +341,7 @@ HRESULT php_com_invoke_helper(php_com_dotnet_object *obj, DISPID id_member,
341
341
}
342
342
343
343
if (msg ) {
344
- php_com_throw_exception (msg TSRMLS_CC );
344
+ php_com_throw_exception (hr , msg TSRMLS_CC );
345
345
efree (msg );
346
346
}
347
347
}
@@ -434,14 +434,16 @@ int php_com_do_invoke(php_com_dotnet_object *obj, char *name, int namelen,
434
434
winerr = php_win_err (hr );
435
435
spprintf (& msg , 0 , "Unable to lookup `%s': %s" , name , winerr );
436
436
LocalFree (winerr );
437
- php_com_throw_exception (msg TSRMLS_CC );
437
+ php_com_throw_exception (hr , msg TSRMLS_CC );
438
438
efree (msg );
439
439
return FAILURE ;
440
440
}
441
441
442
442
return php_com_do_invoke_by_id (obj , dispid , flags , v , nargs , args TSRMLS_CC );
443
443
}
444
444
445
+ /* {{{ proto string com_create_guid()
446
+ Generate a globally unique identifier (GUID) */
445
447
PHP_FUNCTION (com_create_guid )
446
448
{
447
449
GUID retval ;
@@ -460,4 +462,169 @@ PHP_FUNCTION(com_create_guid)
460
462
RETURN_FALSE ;
461
463
}
462
464
}
465
+ /* }}} */
466
+
467
+ /* {{{ proto bool com_event_sink(object comobject, object sinkobject [, mixed sinkinterface])
468
+ Connect events from a COM object to a PHP object */
469
+ PHP_FUNCTION (com_event_sink )
470
+ {
471
+ zval * object , * sinkobject , * sink = NULL ;
472
+ char * dispname = NULL , * typelibname = NULL ;
473
+ zend_bool gotguid = 0 ;
474
+ php_com_dotnet_object * obj ;
475
+ ITypeInfo * typeinfo = NULL ;
476
+
477
+ RETVAL_FALSE ;
478
+
479
+ if (FAILURE == zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "Oo|z/" ,
480
+ & object , php_com_variant_class_entry , & sinkobject , & sink )) {
481
+ RETURN_FALSE ;
482
+ }
483
+
484
+ obj = CDNO_FETCH (object );
485
+
486
+ if (sink && Z_TYPE_P (sink ) == IS_ARRAY ) {
487
+ /* 0 => typelibname, 1 => dispname */
488
+ zval * * tmp ;
489
+
490
+ if (zend_hash_index_find (Z_ARRVAL_P (sink ), 0 , (void * * )& tmp ) == SUCCESS )
491
+ typelibname = Z_STRVAL_PP (tmp );
492
+ if (zend_hash_index_find (Z_ARRVAL_P (sink ), 1 , (void * * )& tmp ) == SUCCESS )
493
+ dispname = Z_STRVAL_PP (tmp );
494
+ } else if (sink != NULL ) {
495
+ convert_to_string (sink );
496
+ dispname = Z_STRVAL_P (sink );
497
+ }
498
+
499
+ typeinfo = php_com_locate_typeinfo (typelibname , obj , dispname , 1 TSRMLS_CC );
500
+
501
+ if (typeinfo ) {
502
+ HashTable * id_to_name ;
503
+
504
+ ALLOC_HASHTABLE (id_to_name );
505
+
506
+ if (php_com_process_typeinfo (typeinfo , id_to_name , 0 , & obj -> sink_id , obj -> code_page TSRMLS_CC )) {
507
+
508
+ /* Create the COM wrapper for this sink */
509
+ obj -> sink_dispatch = php_com_wrapper_export_as_sink (sinkobject , & obj -> sink_id , id_to_name TSRMLS_CC );
510
+
511
+ /* Now hook it up to the source */
512
+ php_com_object_enable_event_sink (obj , TRUE TSRMLS_CC );
513
+ RETVAL_TRUE ;
514
+
515
+ } else {
516
+ FREE_HASHTABLE (id_to_name );
517
+ }
518
+ }
519
+
520
+ if (typeinfo ) {
521
+ ITypeInfo_Release (typeinfo );
522
+ }
523
+
524
+ }
525
+ /* }}} */
526
+
527
+ /* {{{ proto bool com_print_typeinfo(object comobject | string typelib, string dispinterface, bool wantsink)
528
+ Print out a PHP class definition for a dispatchable interface */
529
+ PHP_FUNCTION (com_print_typeinfo )
530
+ {
531
+ zval * arg1 ;
532
+ char * ifacename = NULL ;
533
+ char * typelibname = NULL ;
534
+ int ifacelen ;
535
+ zend_bool wantsink = 0 ;
536
+ php_com_dotnet_object * obj = NULL ;
537
+ ITypeInfo * typeinfo ;
538
+
539
+ if (FAILURE == zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "z/|s!b" , & arg1 , & ifacename ,
540
+ & ifacelen , & wantsink )) {
541
+ RETURN_FALSE ;
542
+ }
543
+
544
+ if (Z_TYPE_P (arg1 ) == IS_OBJECT ) {
545
+ CDNO_FETCH_VERIFY (obj , arg1 );
546
+ } else {
547
+ convert_to_string (arg1 );
548
+ typelibname = Z_STRVAL_P (arg1 );
549
+ }
550
+
551
+ typeinfo = php_com_locate_typeinfo (typelibname , obj , ifacename , wantsink ? 1 : 0 TSRMLS_CC );
552
+ if (typeinfo ) {
553
+ php_com_process_typeinfo (typeinfo , NULL , 1 , NULL , obj ? obj -> code_page : COMG (code_page ) TSRMLS_CC );
554
+ ITypeInfo_Release (typeinfo );
555
+ RETURN_TRUE ;
556
+ } else {
557
+ zend_error (E_WARNING , "Unable to find typeinfo using the parameters supplied" );
558
+ }
559
+ RETURN_FALSE ;
560
+ }
561
+ /* }}} */
562
+
563
+ /* {{{ proto bool com_message_pump([int timeoutms])
564
+ Process COM messages, sleeping for up to timeoutms milliseconds */
565
+ PHP_FUNCTION (com_message_pump )
566
+ {
567
+ long timeoutms = 0 ;
568
+ MSG msg ;
569
+ DWORD result ;
570
+
571
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "|l" , & timeoutms ) == FAILURE )
572
+ RETURN_FALSE ;
573
+
574
+ result = MsgWaitForMultipleObjects (0 , NULL , FALSE, timeoutms , QS_ALLINPUT );
575
+
576
+ if (result == WAIT_OBJECT_0 ) {
577
+ while (PeekMessage (& msg , NULL , 0 , 0 , PM_REMOVE )) {
578
+ TranslateMessage (& msg );
579
+ DispatchMessage (& msg );
580
+ }
581
+ /* we processed messages */
582
+ RETVAL_TRUE ;
583
+ } else {
584
+ /* we did not process messages (timed out) */
585
+ RETVAL_FALSE ;
586
+ }
587
+ }
588
+ /* }}} */
463
589
590
+ /* {{{ proto bool com_load_typelib(string typelib_name [, int case_insensitive])
591
+ Loads a Typelibrary and registers its constants */
592
+ PHP_FUNCTION (com_load_typelib )
593
+ {
594
+ char * name ;
595
+ long namelen ;
596
+ ITypeLib * pTL = NULL ;
597
+ zend_bool cs = TRUE;
598
+ int codepage = COMG (code_page );
599
+ int cached = 0 ;
600
+
601
+ if (FAILURE == zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s|b" , & name , & namelen , & cs )) {
602
+ return ;
603
+ }
604
+
605
+ RETVAL_FALSE ;
606
+
607
+ pTL = php_com_load_typelib_via_cache (name , codepage , & cached TSRMLS_CC );
608
+ if (pTL ) {
609
+ if (cached ) {
610
+ RETVAL_TRUE ;
611
+ } else if (php_com_import_typelib (pTL , cs ? CONST_CS : 0 , codepage TSRMLS_CC ) == SUCCESS ) {
612
+ RETVAL_TRUE ;
613
+ }
614
+
615
+ ITypeLib_Release (pTL );
616
+ pTL = NULL ;
617
+ }
618
+ }
619
+ /* }}} */
620
+
621
+
622
+
623
+ /*
624
+ * Local variables:
625
+ * tab-width: 4
626
+ * c-basic-offset: 4
627
+ * End:
628
+ * vim600: noet sw=4 ts=4 fdm=marker
629
+ * vim<600: noet sw=4 ts=4
630
+ */
0 commit comments