return FALSE;
}
+static gboolean
+cominterop_com_visible (MonoClass* klass)
+{
+ static MonoClass *ComVisibleAttribute = NULL;
+ MonoCustomAttrInfo *cinfo;
+
+ /* Handle the ComVisibleAttribute */
+ if (!ComVisibleAttribute)
+ ComVisibleAttribute = mono_class_from_name (mono_defaults.corlib, "System.Runtime.InteropServices", "ComVisibleAttribute");
+
+ cinfo = mono_custom_attrs_from_class (klass);
+ if (cinfo) {
+ MonoReflectionComVisibleAttribute *attr = (MonoReflectionComVisibleAttribute*)mono_custom_attrs_get_attr (cinfo, ComVisibleAttribute);
+
+ if (!attr)
+ return FALSE;
+ if (!cinfo->cached)
+ mono_custom_attrs_free (cinfo);
+
+ if (attr->visible)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void cominterop_raise_hr_exception (int hr)
+{
+ static MonoMethod* throw_exception_for_hr = NULL;
+ MonoException* ex;
+ void* params[1] = {&hr};
+ if (!throw_exception_for_hr)
+ throw_exception_for_hr = mono_class_get_method_from_name (mono_defaults.marshal_class, "GetExceptionForHR", 1);
+ ex = (MonoException*)mono_runtime_invoke (throw_exception_for_hr, NULL, params, NULL);
+ mono_raise_exception (ex);
+}
+
/**
* cominterop_get_interface:
* @obj: managed wrapper object containing COM object
g_assert(found);
hr = ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (obj->iunknown, iid, &itf);
if (hr < 0 && throw_exception) {
- static MonoMethod* throw_exception_for_hr = NULL;
- MonoException* ex;
- void* params[1] = {&hr};
- if (!throw_exception_for_hr)
- throw_exception_for_hr = mono_class_get_method_from_name (mono_defaults.marshal_class, "GetExceptionForHR", 1);
- ex = (MonoException*)mono_runtime_invoke (throw_exception_for_hr, NULL, params, NULL);
- mono_raise_exception (ex);
+ cominterop_raise_hr_exception (hr);
}
if (hr >= 0 && itf) {
if (t->byref) {
mono_mb_emit_byte (mb, CEE_LDIND_I);
+ /* A Nullable<T> type don't have a boxed form, it's either null or a boxed T.
+ * So to make this work we unbox it to a local variablee and push a reference to that.
+ */
+ if (t->type == MONO_TYPE_GENERICINST && mono_class_is_nullable (mono_class_from_mono_type (t))) {
+ int tmp_nullable_local = mono_mb_add_local (mb, &mono_class_from_mono_type (t)->byval_arg);
+
+ mono_mb_emit_op (mb, CEE_UNBOX_ANY, mono_class_from_mono_type (t));
+ mono_mb_emit_stloc (mb, tmp_nullable_local);
+ mono_mb_emit_ldloc_addr (mb, tmp_nullable_local);
+ }
continue;
}
case MONO_TYPE_BOOLEAN:
case MONO_TYPE_I1:
case MONO_TYPE_U1:
+ case MONO_TYPE_CHAR:
case MONO_TYPE_I2:
case MONO_TYPE_U2:
case MONO_TYPE_I4:
mono_loader_unlock ();
clause->flags = MONO_EXCEPTION_CLAUSE_FINALLY;
+ mono_loader_lock ();
+
if (!enter_method) {
MonoMethodDesc *desc;
mono_method_desc_free (desc);
}
+ mono_loader_unlock ();
+
/* Push this or the type object */
if (method->flags & METHOD_ATTRIBUTE_STATIC) {
/* We have special handling for this in the JIT */
#ifndef DISABLE_COM
+#define MONO_S_OK 0x00000000L
+#define MONO_E_NOINTERFACE 0x80004002L
+#define MONO_E_NOTIMPL 0x80004001L
+
+static gboolean cominterop_can_support_dispatch (MonoClass* klass)
+{
+ if (!(klass->flags & TYPE_ATTRIBUTE_PUBLIC) )
+ return FALSE;
+
+ if (!cominterop_com_visible (klass))
+ return FALSE;
+
+ return TRUE;
+}
+
static void*
cominterop_get_idispatch_for_object (MonoObject* object)
{
mono_defaults.idispatch_class, TRUE);
}
else {
+ MonoClass* klass = mono_object_class (object);
+ if (!cominterop_can_support_dispatch (klass) )
+ cominterop_raise_hr_exception (MONO_E_NOINTERFACE);
return cominterop_get_ccw (object, mono_defaults.idispatch_class);
}
}
if (!object)
return NULL;
+ mono_init_com_types ();
+
if (cominterop_object_is_rcw (object)) {
MonoClass *klass = NULL;
MonoRealProxy* real_proxy = NULL;
ves_icall_System_Runtime_InteropServices_Marshal_GetIDispatchForObjectInternal (MonoObject* object)
{
#ifndef DISABLE_COM
+ mono_init_com_types ();
+
return cominterop_get_idispatch_for_object (object);
#else
g_assert_not_reached ();
}
static gboolean
-cominterop_finalizer (gpointer key, gpointer value, gpointer user_data)
+cominterop_rcw_interface_finalizer (gpointer key, gpointer value, gpointer user_data)
{
ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (value);
return TRUE;
g_hash_table_remove (rcw_hash, obj->iunknown);
}
- g_hash_table_foreach_remove (obj->itf_hash, cominterop_finalizer, NULL);
+ g_hash_table_foreach_remove (obj->itf_hash, cominterop_rcw_interface_finalizer, NULL);
+ g_hash_table_destroy (obj->itf_hash);
ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (obj->iunknown);
obj->itf_hash = obj->iunknown = NULL;
mono_cominterop_unlock ();
}
}
+#ifndef DISABLE_COM
+
+static gboolean
+cominterop_rcw_finalizer (gpointer key, gpointer value, gpointer user_data)
+{
+ guint32 gchandle = 0;
+
+ gchandle = GPOINTER_TO_UINT (value);
+ if (gchandle) {
+ MonoComInteropProxy* proxy = (MonoComInteropProxy*)mono_gchandle_get_target (gchandle);
+
+ if (proxy) {
+ if (proxy->com_object->itf_hash) {
+ g_hash_table_foreach_remove (proxy->com_object->itf_hash, cominterop_rcw_interface_finalizer, NULL);
+ g_hash_table_destroy (proxy->com_object->itf_hash);
+ }
+ if (proxy->com_object->iunknown)
+ ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (proxy->com_object->iunknown);
+ proxy->com_object->itf_hash = proxy->com_object->iunknown = NULL;
+ }
+
+ mono_gchandle_free (gchandle);
+ }
+
+ return TRUE;
+}
+
+void
+cominterop_release_all_rcws ()
+{
+ if (!rcw_hash)
+ return;
+
+ mono_cominterop_lock ();
+
+ g_hash_table_foreach_remove (rcw_hash, cominterop_rcw_finalizer, NULL);
+ g_hash_table_destroy (rcw_hash);
+ rcw_hash = NULL;
+
+ mono_cominterop_unlock ();
+}
+
+#endif
+
gpointer
ves_icall_System_ComObject_GetInterfaceInternal (MonoComObject* obj, MonoReflectionType* type, MonoBoolean throw_exception)
{
return ref_count;
}
-#define MONO_S_OK 0x00000000L
-#define MONO_E_NOINTERFACE 0x80004002L
-#define MONO_E_NOTIMPL 0x80004001L
-
#ifdef PLATFORM_WIN32
static const IID MONO_IID_IMarshal = {0x3, 0x0, 0x0, {0xC0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46}};
#endif
/* handle IDispatch special */
if (cominterop_class_guid_equal (riid, mono_defaults.idispatch_class)) {
+ if (!cominterop_can_support_dispatch (klass))
+ return MONO_E_NOINTERFACE;
+
*ppv = cominterop_get_ccw (object, mono_defaults.idispatch_class);
/* remember to addref on QI */
cominterop_ccw_addref (*ppv);