summaryrefslogtreecommitdiff
path: root/ext/com_dotnet/com_dotnet.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/com_dotnet/com_dotnet.c')
-rw-r--r--ext/com_dotnet/com_dotnet.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/ext/com_dotnet/com_dotnet.c b/ext/com_dotnet/com_dotnet.c
index 0aa1a2a9c7..9698fb3419 100644
--- a/ext/com_dotnet/com_dotnet.c
+++ b/ext/com_dotnet/com_dotnet.c
@@ -198,7 +198,8 @@ PHP_FUNCTION(com_dotnet_create_instance)
IUnknown *unk = NULL;
php_com_initialize(TSRMLS_C);
- if (COMG(dotnet_runtime_stuff) == NULL) {
+ stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff);
+ if (stuff == NULL) {
hr = dotnet_init(&where TSRMLS_CC);
if (FAILED(hr)) {
char buf[1024];
@@ -207,12 +208,38 @@ PHP_FUNCTION(com_dotnet_create_instance)
if (err)
LocalFree(err);
php_com_throw_exception(hr, buf TSRMLS_CC);
+ ZEND_CTOR_MAKE_NULL();
+ return;
+ }
+ stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff);
+
+ } else if (stuff->dotnet_domain == NULL) {
+ where = "ICorRuntimeHost_GetDefaultDomain";
+ hr = ICorRuntimeHost_GetDefaultDomain(stuff->dotnet_host, &unk);
+ if (FAILED(hr)) {
+ char buf[1024];
+ char *err = php_win32_error_to_msg(hr);
+ snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] %s", where, err);
+ if (err)
+ LocalFree(err);
+ php_com_throw_exception(hr, buf TSRMLS_CC);
ZVAL_NULL(object);
return;
}
- }
- stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff);
+ where = "QI: System._AppDomain";
+ hr = IUnknown_QueryInterface(unk, &IID_mscorlib_System_AppDomain, (LPVOID*)&stuff->dotnet_domain);
+ if (FAILED(hr)) {
+ char buf[1024];
+ char *err = php_win32_error_to_msg(hr);
+ snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] %s", where, err);
+ if (err)
+ LocalFree(err);
+ php_com_throw_exception(hr, buf TSRMLS_CC);
+ ZVAL_NULL(object);
+ return;
+ }
+ }
obj = CDNO_FETCH(object);
@@ -221,7 +248,7 @@ PHP_FUNCTION(com_dotnet_create_instance)
&datatype_name, &datatype_name_len,
&obj->code_page)) {
php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid arguments!" TSRMLS_CC);
- ZVAL_NULL(object);
+ ZEND_CTOR_MAKE_NULL();
return;
}
@@ -287,7 +314,7 @@ PHP_FUNCTION(com_dotnet_create_instance)
LocalFree(err);
}
php_com_throw_exception(hr, buf TSRMLS_CC);
- ZVAL_NULL(object);
+ ZEND_CTOR_MAKE_NULL();
return;
}
}