Author: joncham
Date: 2006-08-10 22:28:50 -0400 (Thu, 10 Aug 2006)
New Revision: 63630
Modified:
trunk/mcs/class/corlib/Mono.Interop/ChangeLog
trunk/mcs/class/corlib/Mono.Interop/ComInteropProxy.cs
trunk/mcs/class/corlib/System.Runtime.InteropServices/ChangeLog
trunk/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ActivationServices.cs
trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ChangeLog
trunk/mcs/class/corlib/System/ChangeLog
trunk/mcs/class/corlib/System/MonoType.cs
trunk/mcs/class/corlib/System/__ComObject.cs
Log:
2006-08-10 Jonathan Chambers <[EMAIL PROTECTED]>
* ComInteropProxy.cs: Fix default constructor being always
being called.
* Marshal.cs: Implement GetIDispatchForObject.
* __ComObject.cs: Added defintion of IDispatch interface, and
property. Get CLSID of supertype for creation if class not
ComImport attributed (allows for inheritance of RCW).
* MonoType.cs: Implement IsCOMObjectImpl.
Modified: trunk/mcs/class/corlib/Mono.Interop/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Mono.Interop/ChangeLog 2006-08-11 02:26:15 UTC
(rev 63629)
+++ trunk/mcs/class/corlib/Mono.Interop/ChangeLog 2006-08-11 02:28:50 UTC
(rev 63630)
@@ -1,3 +1,8 @@
+2006-08-10 Jonathan Chambers <[EMAIL PROTECTED]>
+
+ * ComInteropProxy.cs: Fix default constructor being always
+ being called.
+
2006-07-28 Jonathan Chambers <[EMAIL PROTECTED]>
* ComInteropProxy.cs: Added support for marshalling objects.
Modified: trunk/mcs/class/corlib/Mono.Interop/ComInteropProxy.cs
===================================================================
--- trunk/mcs/class/corlib/Mono.Interop/ComInteropProxy.cs 2006-08-11
02:26:15 UTC (rev 63629)
+++ trunk/mcs/class/corlib/Mono.Interop/ComInteropProxy.cs 2006-08-11
02:28:50 UTC (rev 63630)
@@ -68,10 +68,18 @@
public ComInteropProxy (Type t)
: base (t)
{
- com_object = new __ComObject (t);
- iunknown_hashtable.Add (com_object.IUnknown, new
ComInteropProxyEntry (1, new WeakReference(this)));
+ // object only created here
+ // .ctor is called later
+ com_object = __ComObject.CreateRCW (t);
}
+ internal void CacheProxy ()
+ {
+ // called from unmanaged code after .ctor is invoked
+ // we need .ctor to create unmanaged object and thus
IUnknown property value
+ iunknown_hashtable.Add (com_object.IUnknown, new
ComInteropProxyEntry (1, new WeakReference (this)));
+ }
+
internal ComInteropProxy (IntPtr pUnk)
: this (pUnk, typeof (__ComObject))
{
Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog 2006-08-11 02:26:15 UTC (rev
63629)
+++ trunk/mcs/class/corlib/System/ChangeLog 2006-08-11 02:28:50 UTC (rev
63630)
@@ -1,3 +1,10 @@
+2006-08-10 Jonathan Chambers <[EMAIL PROTECTED]>
+
+ * __ComObject.cs: Added defintion of IDispatch interface, and
+ property. Get CLSID of supertype for creation if class not
+ ComImport attributed (allows for inheritance of RCW).
+ * MonoType.cs: Implement IsCOMObjectImpl.
+
2006-08-09 Atsushi Enomoto <[EMAIL PROTECTED]>
* DateTime.cs : fixed X509Certificate() case that regressed only
Modified: trunk/mcs/class/corlib/System/MonoType.cs
===================================================================
--- trunk/mcs/class/corlib/System/MonoType.cs 2006-08-11 02:26:15 UTC (rev
63629)
+++ trunk/mcs/class/corlib/System/MonoType.cs 2006-08-11 02:28:50 UTC (rev
63630)
@@ -290,10 +290,8 @@
[MethodImplAttribute(MethodImplOptions.InternalCall)]
protected extern override bool IsByRefImpl ();
- protected override bool IsCOMObjectImpl ()
- {
- return false;
- }
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ protected extern override bool IsCOMObjectImpl ();
[MethodImplAttribute(MethodImplOptions.InternalCall)]
protected extern override bool IsPointerImpl ();
Modified: trunk/mcs/class/corlib/System/__ComObject.cs
===================================================================
--- trunk/mcs/class/corlib/System/__ComObject.cs 2006-08-11 02:26:15 UTC
(rev 63629)
+++ trunk/mcs/class/corlib/System/__ComObject.cs 2006-08-11 02:28:50 UTC
(rev 63630)
@@ -74,6 +74,20 @@
public __ComObject ()
{
+ // call CoInitialize once per thread
+ if (!coinitialized) {
+ CoInitialize (IntPtr.Zero);
+ coinitialized = true;
+ }
+
+ hashtable = new Hashtable ();
+
+ IntPtr ppv;
+ Type t = GetType ();
+ int hr = CoCreateInstance (GetCLSID (t), IntPtr.Zero,
0x1 | 0x4 | 0x10, IID_IUnknown, out ppv);
+ Marshal.ThrowExceptionForHR (hr);
+
+ SetIUnknown (ppv);
}
internal __ComObject (Type t)
@@ -87,12 +101,27 @@
hashtable = new Hashtable ();
IntPtr ppv;
- int hr = CoCreateInstance (t.GUID, IntPtr.Zero, 0x1 |
0x4 | 0x10, IID_IUnknown, out ppv);
+ int hr = CoCreateInstance (GetCLSID (t), IntPtr.Zero,
0x1 | 0x4 | 0x10, IID_IUnknown, out ppv);
Marshal.ThrowExceptionForHR (hr);
SetIUnknown (ppv);
}
+ private Guid GetCLSID (Type t)
+ {
+ if (t.IsImport)
+ return t.GUID;
+
+ // look at supertypes
+ Type super = t.BaseType;
+ while (super != typeof (object)) {
+ if (super.IsImport)
+ return super.GUID;
+ super = super.BaseType;
+ }
+ throw new COMException ("Could not find base COM type
for type " + t.ToString());
+ }
+
internal __ComObject (IntPtr pItf)
{
hashtable = new Hashtable ();
@@ -155,6 +184,17 @@
}
}
+ internal IntPtr IDispatch
+ {
+ get
+ {
+ IntPtr pUnk = GetInterface (typeof
(IDispatchMono));
+ if (pUnk == IntPtr.Zero)
+ throw new InvalidComObjectException
("COM object that has been separated from its underlying RCW cannot be used.");
+ return pUnk;
+ }
+ }
+
internal static Guid IID_IUnknown
{
get
@@ -171,6 +211,11 @@
}
}
+ [Guid ("00020400-0000-0000-C000-000000000046")]
+ internal interface IDispatchMono
+ {
+ }
+
public override bool Equals (object obj)
{
if (obj == null)
Modified: trunk/mcs/class/corlib/System.Runtime.InteropServices/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Runtime.InteropServices/ChangeLog
2006-08-11 02:26:15 UTC (rev 63629)
+++ trunk/mcs/class/corlib/System.Runtime.InteropServices/ChangeLog
2006-08-11 02:28:50 UTC (rev 63630)
@@ -1,3 +1,7 @@
+2006-08-09 Jonathan Chambers <[EMAIL PROTECTED]>
+
+ * Marshal.cs: Implement GetIDispatchForObject.
+
2006-08-07 Gert Driesen <[EMAIL PROTECTED]>
* Marshal.cs: Added stubs for GetTypeLibGuid (ITypeLib), GetTypeLibLcid
Modified: trunk/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
===================================================================
--- trunk/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
2006-08-11 02:26:15 UTC (rev 63629)
+++ trunk/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
2006-08-11 02:28:50 UTC (rev 63630)
@@ -308,7 +308,14 @@
}
[MonoTODO]
- public static IntPtr GetIDispatchForObject (object o) {
+ public static IntPtr GetIDispatchForObject (object o)
+ { // only handle case of RCW objects for
now
+ __ComObject co = o as __ComObject;
+ if (co != null) {
+ IntPtr pUnk = co.IDispatch;
+ AddRef (pUnk);
+ return pUnk;
+ }
throw new NotImplementedException ();
}
Modified:
trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ActivationServices.cs
===================================================================
---
trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ActivationServices.cs
2006-08-11 02:26:15 UTC (rev 63629)
+++
trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ActivationServices.cs
2006-08-11 02:28:50 UTC (rev 63630)
@@ -204,8 +204,9 @@
if (type.IsContextful)
return
RemotingServices.CreateClientProxyForContextBound (type, null);
- if (type.IsImport)
- return RemotingServices.CreateClientProxyForComInterop (type);
+ if (type.IsCOMObject) {
+ return
RemotingServices.CreateClientProxyForComInterop (type);
+ }
return null;
}
Modified: trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ChangeLog
2006-08-11 02:26:15 UTC (rev 63629)
+++ trunk/mcs/class/corlib/System.Runtime.Remoting.Activation/ChangeLog
2006-08-11 02:28:50 UTC (rev 63630)
@@ -1,3 +1,7 @@
+2006-08-09 Jonathan Chambers <[EMAIL PROTECTED]>
+
+ * ActivationServices.cs: Check type.IsCOMObject rather than
type.IsImport.
+
2006-07-15 Jonathan Chambers <[EMAIL PROTECTED]>
* ActivationServices.cs: Begin implementing COM Interop.
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches