2003-08-15 00:49:56 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2014-09-20 00:33:14 +08:00
|
|
|
| PHP Version 7 |
|
2003-08-15 00:49:56 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2017-01-02 23:30:12 +08:00
|
|
|
| Copyright (c) 1997-2017 The PHP Group |
|
2003-08-15 00:49:56 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2003-08-15 00:49:56 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2003-08-15 00:49:56 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Wez Furlong <wez@thebrainroom.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "php_com_dotnet.h"
|
|
|
|
#include "php_com_dotnet_internal.h"
|
2004-02-12 18:43:27 +08:00
|
|
|
#include "Zend/zend_exceptions.h"
|
2003-08-15 00:49:56 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
void php_com_throw_exception(HRESULT code, char *message)
|
2003-08-15 00:49:56 +08:00
|
|
|
{
|
2004-01-08 05:00:07 +08:00
|
|
|
int free_msg = 0;
|
|
|
|
if (message == NULL) {
|
2010-11-26 07:06:12 +08:00
|
|
|
message = php_win32_error_to_msg(code);
|
2004-01-08 05:00:07 +08:00
|
|
|
free_msg = 1;
|
|
|
|
}
|
2014-10-28 23:52:49 +08:00
|
|
|
#if SIZEOF_ZEND_LONG == 8
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(php_com_exception_class_entry, message, (zend_long)(uint32_t)code);
|
2014-10-28 23:52:49 +08:00
|
|
|
#else
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(php_com_exception_class_entry, message, (zend_long)code);
|
2014-10-28 23:52:49 +08:00
|
|
|
#endif
|
2004-01-08 05:00:07 +08:00
|
|
|
if (free_msg) {
|
2004-05-09 22:28:19 +08:00
|
|
|
LocalFree(message);
|
2004-01-08 05:00:07 +08:00
|
|
|
}
|
2003-08-15 00:49:56 +08:00
|
|
|
}
|
|
|
|
|
2012-05-25 06:22:25 +08:00
|
|
|
PHP_COM_DOTNET_API void php_com_wrap_dispatch(zval *z, IDispatch *disp,
|
2014-12-14 06:06:14 +08:00
|
|
|
int codepage)
|
2003-08-15 00:49:56 +08:00
|
|
|
{
|
|
|
|
php_com_dotnet_object *obj;
|
|
|
|
|
|
|
|
obj = emalloc(sizeof(*obj));
|
|
|
|
memset(obj, 0, sizeof(*obj));
|
|
|
|
obj->code_page = codepage;
|
|
|
|
obj->ce = php_com_variant_class_entry;
|
2005-11-27 20:19:04 +08:00
|
|
|
obj->zo.ce = php_com_variant_class_entry;
|
2003-08-15 00:49:56 +08:00
|
|
|
|
|
|
|
VariantInit(&obj->v);
|
|
|
|
V_VT(&obj->v) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&obj->v) = disp;
|
|
|
|
|
|
|
|
IDispatch_AddRef(V_DISPATCH(&obj->v));
|
|
|
|
IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &obj->typeinfo);
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_std_init(&obj->zo, php_com_variant_class_entry);
|
2014-08-11 22:37:26 +08:00
|
|
|
obj->zo.handlers = &php_com_object_handlers;
|
|
|
|
ZVAL_OBJ(z, &obj->zo);
|
2003-08-15 00:49:56 +08:00
|
|
|
}
|
|
|
|
|
2012-05-25 06:22:25 +08:00
|
|
|
PHP_COM_DOTNET_API void php_com_wrap_variant(zval *z, VARIANT *v,
|
2014-12-14 06:06:14 +08:00
|
|
|
int codepage)
|
2003-08-15 00:49:56 +08:00
|
|
|
{
|
|
|
|
php_com_dotnet_object *obj;
|
|
|
|
|
|
|
|
obj = emalloc(sizeof(*obj));
|
|
|
|
memset(obj, 0, sizeof(*obj));
|
|
|
|
obj->code_page = codepage;
|
|
|
|
obj->ce = php_com_variant_class_entry;
|
2005-11-27 20:19:04 +08:00
|
|
|
obj->zo.ce = php_com_variant_class_entry;
|
2003-08-15 00:49:56 +08:00
|
|
|
|
|
|
|
VariantInit(&obj->v);
|
2004-01-08 05:00:07 +08:00
|
|
|
VariantCopyInd(&obj->v, v);
|
2007-02-02 23:27:35 +08:00
|
|
|
obj->modified = 0;
|
2003-08-15 00:49:56 +08:00
|
|
|
|
2007-02-02 23:44:06 +08:00
|
|
|
if ((V_VT(&obj->v) == VT_DISPATCH) && (V_DISPATCH(&obj->v) != NULL)) {
|
2003-08-15 00:49:56 +08:00
|
|
|
IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &obj->typeinfo);
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_std_init(&obj->zo, php_com_variant_class_entry);
|
2014-08-11 22:37:26 +08:00
|
|
|
obj->zo.handlers = &php_com_object_handlers;
|
|
|
|
ZVAL_OBJ(z, &obj->zo);
|
2003-08-15 00:49:56 +08:00
|
|
|
}
|
2004-01-08 05:00:07 +08:00
|
|
|
|
|
|
|
/* this is a convenience function for fetching a particular
|
|
|
|
* element from a (possibly multi-dimensional) safe array */
|
2014-12-14 06:06:14 +08:00
|
|
|
PHP_COM_DOTNET_API int php_com_safearray_get_elem(VARIANT *array, VARIANT *dest, LONG dim1)
|
2004-01-08 05:00:07 +08:00
|
|
|
{
|
|
|
|
UINT dims;
|
|
|
|
LONG lbound, ubound;
|
|
|
|
LONG indices[1];
|
|
|
|
VARTYPE vt;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-01-08 05:00:07 +08:00
|
|
|
if (!V_ISARRAY(array)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-01-08 05:00:07 +08:00
|
|
|
dims = SafeArrayGetDim(V_ARRAY(array));
|
|
|
|
|
|
|
|
if (dims != 1) {
|
2014-12-14 06:06:14 +08:00
|
|
|
php_error_docref(NULL, E_WARNING,
|
2004-01-08 05:00:07 +08:00
|
|
|
"Can only handle single dimension variant arrays (this array has %d)", dims);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-01-08 05:00:07 +08:00
|
|
|
if (FAILED(SafeArrayGetVartype(V_ARRAY(array), &vt)) || vt == VT_EMPTY) {
|
|
|
|
vt = V_VT(array) & ~VT_ARRAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine the bounds */
|
|
|
|
SafeArrayGetLBound(V_ARRAY(array), 1, &lbound);
|
|
|
|
SafeArrayGetUBound(V_ARRAY(array), 1, &ubound);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-01-08 05:00:07 +08:00
|
|
|
/* check bounds */
|
|
|
|
if (dim1 < lbound || dim1 > ubound) {
|
2014-12-14 06:06:14 +08:00
|
|
|
php_com_throw_exception(DISP_E_BADINDEX, "index out of bounds");
|
2004-01-08 05:00:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-01-08 05:00:07 +08:00
|
|
|
/* now fetch that element */
|
|
|
|
VariantInit(dest);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-01-08 05:00:07 +08:00
|
|
|
indices[0] = dim1;
|
|
|
|
|
|
|
|
if (vt == VT_VARIANT) {
|
|
|
|
SafeArrayGetElement(V_ARRAY(array), indices, dest);
|
|
|
|
} else {
|
|
|
|
V_VT(dest) = vt;
|
|
|
|
/* store the value into "lVal" member of the variant.
|
|
|
|
* This works because it is a union; since we know the variant
|
|
|
|
* type, we end up with a working variant */
|
|
|
|
SafeArrayGetElement(V_ARRAY(array), indices, &dest->lVal);
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:22:58 +08:00
|
|
|
return 1;
|
2004-01-08 05:00:07 +08:00
|
|
|
}
|