Beispiel #1
0
        internal void Initialize(Type t)
        {
            InitializeApartmentDetails();
            // Guard multiple invocation.
            if (iunknown != IntPtr.Zero)
            {
                return;
            }

            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 void Initialize(Type t)
        {
            if (this.iunknown != IntPtr.Zero)
            {
                return;
            }
            ObjectCreationDelegate objectCreationCallback = ExtensibleClassFactory.GetObjectCreationCallback(t);

            if (objectCreationCallback != null)
            {
                this.iunknown = objectCreationCallback(IntPtr.Zero);
                if (this.iunknown == IntPtr.Zero)
                {
                    throw new COMException(string.Format("ObjectCreationDelegate for type {0} failed to return a valid COM object", t));
                }
            }
            else
            {
                int errorCode = __ComObject.CoCreateInstance(__ComObject.GetCLSID(t), IntPtr.Zero, 21u, __ComObject.IID_IUnknown, out this.iunknown);
                Marshal.ThrowExceptionForHR(errorCode);
            }
        }
Beispiel #3
0
        internal static IntPtr CreateIUnknown(Type t)
        {
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(t.TypeHandle);

            IntPtr iunknown;
            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);
            }

            return(iunknown);
        }
Beispiel #4
0
 static TestClass()
 {
     ExtensibleClassFactory.RegisterObjectCreationCallback(new ObjectCreationDelegate(CreateObject));
     ;
 }