2007-07-06 Jonathan Chambers <joncham@gmail.com>
authorJonathan Chambers <joncham@gmail.com>
Fri, 6 Jul 2007 16:44:09 +0000 (16:44 -0000)
committerJonathan Chambers <joncham@gmail.com>
Fri, 6 Jul 2007 16:44:09 +0000 (16:44 -0000)
* ExtensibleClassFactory.cs: Fix ExtensibleClassFactory.
* __ComObject.cs: Support ExtensibleClassFactory.

svn path=/trunk/mcs/; revision=81494

mcs/class/corlib/System.Runtime.InteropServices/ChangeLog
mcs/class/corlib/System.Runtime.InteropServices/ExtensibleClassFactory.cs
mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/__ComObject.cs

index 4eb2e59da6c18947f481b58c51d6316417806ad1..f2b4485ea77e83e09eec534254a4c747c0e163fe 100644 (file)
@@ -1,7 +1,11 @@
+2007-07-06  Jonathan Chambers  <joncham@gmail.com>
+
+       * ExtensibleClassFactory.cs: Fix ExtensibleClassFactory.
+
 2007-06-22  Jonathan Chambers  <joncham@gmail.com>
 
-       * __ComObject.cs (ThrowExceptionForHR): Implement/consolidate.
-       * __ComObject.cs (GetExceptionForHR): Implement/consolidate.
+       * Marshal.cs (ThrowExceptionForHR): Implement/consolidate.
+       * Marshal.cs (GetExceptionForHR): Implement/consolidate.
 
 2007-05-11  Jonathan Chambers  <joncham@gmail.com>
 
index 0f5e3c22db11694b2b24b9157af6199145c7ad11..54a826a1dd874a3068f9a8c16b091f224dba37a5 100644 (file)
@@ -31,8 +31,8 @@
 //
 
 using System.Diagnostics;
-using System.Threading;
 using System.Collections;
+using System.Reflection;
 
 namespace System.Runtime.InteropServices
 {
@@ -57,11 +57,20 @@ namespace System.Runtime.InteropServices
                        return hashtable[t] as ObjectCreationDelegate;
                }
 
-               public static void RegisterObjectCreationCallback (ObjectCreationDelegate callback)
-               {
+               public static void RegisterObjectCreationCallback (ObjectCreationDelegate callback) {
+                       int i = 1;
                        StackTrace trace = new StackTrace (false);
-                       StackFrame frame = trace.GetFrame (0);
-                       hashtable.Add (frame.GetMethod ().DeclaringType, callback);
+                       while (i < trace.FrameCount) {
+                               StackFrame frame = trace.GetFrame (i);
+                               MethodBase m = frame.GetMethod ();
+                               if (m.MemberType == MemberTypes.Constructor && m.IsStatic) {
+                                       hashtable.Add (m.DeclaringType, callback);
+                                       return;
+                               }
+                               i++;
+                       }
+                       throw new System.InvalidOperationException (
+                               "RegisterObjectCreationCallback must be called from .cctor of class derived from ComImport type.");
                }
        }
 }
index 7dfc5e97bd4cf20dc65b04be81dacf1e106826b6..c3b28e4c11a5db92c6a4dd872e8b705bcfee9cdf 100644 (file)
@@ -1,3 +1,7 @@
+2007-07-06  Jonathan Chambers  <joncham@gmail.com>
+
+       * __ComObject.cs: Support ExtensibleClassFactory.
+
 2007-07-06  Aaron Bockover  <abockover@novell.com>
 
        * Environment.cs (InternalGetFolderPath): Try reading some
index 18adc861d72696c2025fc99b195870ac8de68b7d..acfd093db968365cbec830b1e400fd07465fda5d 100644 (file)
@@ -71,14 +71,28 @@ namespace System
                public __ComObject ()
                {
                        Type t = GetType ();
-                       int hr = CoCreateInstance (GetCLSID (t), IntPtr.Zero, 0x1 | 0x4 | 0x10, IID_IUnknown, out iunknown);
-                       Marshal.ThrowExceptionForHR (hr);
+                       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);
+                       }
                }
 
-               internal __ComObject (Type t)
-               {
-                       int hr = CoCreateInstance (GetCLSID (t), IntPtr.Zero, 0x1 | 0x4 | 0x10, IID_IUnknown, out iunknown);
-                       Marshal.ThrowExceptionForHR (hr);
+               internal __ComObject (Type t) {
+                       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);
+                       }
                }
 
                internal __ComObject (IntPtr pItf)