+2009-07-11 Robert Jordan <robertj@gmx.net>
+
+ * ComInteropProxy.cs: Implement CreateProxy. Hide public/internal
+ ctors forcing CreateProxy's usage. Hide CacheProxy since the
+ runtime is able to lookup it anyways.
+ Fixes bug #520437.
+
2007-07-26 Jonathan Chambers <joncham@gmail.com>
* ComInteropProxy.cs: Call Marshal.Release after Marshal.QI
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static ComInteropProxy FindProxy (IntPtr pItf);
- public ComInteropProxy (Type t)
+ // Private. Objects must be created with CreateProxy.
+ ComInteropProxy (Type t)
: base (t)
{
// object only created here
com_object = __ComObject.CreateRCW (t);
}
- internal void CacheProxy ()
+ void CacheProxy ()
{
// called from unmanaged code after .ctor is invoked
// we need .ctor to create unmanaged object and thus IUnknown property value
AddProxy (com_object.IUnknown, this);
}
- internal ComInteropProxy (IntPtr pUnk)
- : this (pUnk, typeof (__ComObject))
- {
+ ComInteropProxy (IntPtr pUnk)
+ : this (pUnk, typeof (__ComObject))
+ {
}
internal ComInteropProxy (IntPtr pUnk, Type t)
}
}
+ // Gets the proxy of the specified COM type. If the COM type is
+ // already known, a cached proxy will be returned.
+ internal static ComInteropProxy CreateProxy (Type t)
+ {
+ ComInteropProxy proxy = new ComInteropProxy (t);
+ proxy.com_object.Initialize (t);
+
+ ComInteropProxy cachedProxy = FindProxy (proxy.com_object.IUnknown);
+ if (cachedProxy != null) {
+ // check that the COM type of the cached proxy matches
+ // the requested type. See 2nd part of bug #520437.
+ Type cachedType = cachedProxy.com_object.GetType ();
+ if (cachedType != t)
+ throw new InvalidCastException (String.Format ("Unable to cast object of type '{0}' to type '{1}'.", cachedType, t));
+ return cachedProxy;
+ }
+ return proxy;
+ }
+
public override IMessage Invoke (IMessage msg)
{
Console.WriteLine ("Invoke");
+2009-07-11 Robert Jordan <robertj@gmx.net>
+
+ * RemotingServices.cs: Track ComInteropProxy's changes.
+
2009-04-18 Mark Probst <mark.probst@gmail.com>
* RemotingServices.cs (GetDomainProxy): Make a copy of the array
internal static object CreateClientProxyForComInterop (Type type)
{
- Mono.Interop.ComInteropProxy proxy = new Mono.Interop.ComInteropProxy (type);
+ Mono.Interop.ComInteropProxy proxy = Mono.Interop.ComInteropProxy.CreateProxy (type);
return proxy.GetTransparentProxy ();
}
+2009-07-19 Robert Jordan <robertj@gmx.net>
+
+ * __ComObject.cs: Factor out Initialize method and expose it to
+ ComInteropProxy. Fixes bug #520437.
+
2009-07-14 Rodrigo Kumpera <rkumpera@novell.com>
* Attribute.cs (GetCustomAttributes): Pass typeof(Attribute)
public __ComObject ()
{
- Type t = GetType ();
- ObjectCreationDelegate ocd = ExtensibleClassFactory.GetObjectCreationCallback (t);
- if (ocd != null) {
- iunknown = ocd (IntPtr.Zero);
- if (iunknown == IntPtr.Zero)
- throw new COMException (string.Format("ObjectCreationDelegate for type {0} failed to return a valid COM object", t));
- } else {
- int hr = CoCreateInstance (GetCLSID (t), IntPtr.Zero, 0x1 | 0x4 | 0x10, IID_IUnknown, out iunknown);
- Marshal.ThrowExceptionForHR (hr);
- }
+ Initialize (GetType ());
}
internal __ComObject (Type t) {
+ Initialize (t);
+ }
+
+ internal __ComObject (IntPtr pItf)
+ {
+ Guid iid = IID_IUnknown;
+ int hr = Marshal.QueryInterface (pItf, ref iid, out iunknown);
+ Marshal.ThrowExceptionForHR (hr);
+ }
+
+ internal void Initialize (Type t)
+ {
+ // Guard multiple invocation.
+ if (iunknown != IntPtr.Zero)
+ return;
+
ObjectCreationDelegate ocd = ExtensibleClassFactory.GetObjectCreationCallback (t);
if (ocd != null) {
iunknown = ocd (IntPtr.Zero);
}
}
- internal __ComObject (IntPtr pItf)
- {
- Guid iid = IID_IUnknown;
- int hr = Marshal.QueryInterface (pItf, ref iid, out iunknown);
- Marshal.ThrowExceptionForHR (hr);
- }
-
private static Guid GetCLSID (Type t)
{
if (t.IsImport)