示例#1
0
 public static int CoCreateInstance(
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
     IntPtr pUnkOuter,
     CLSCTX dwClsContext,
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid,
     out IntPtr rReturnedComObject
     )
 {
     rReturnedComObject = IntPtr.Zero;
     return -1;
 }
示例#2
0
 /// <summary>
 /// Creates a COM object with the specified interface.
 /// </summary>
 /// <param name="iid">The interface identifier. This parameter is a reference to a GUID that identifies the interface that the caller requests be activated. The caller will use this interface to communicate with the COM object.</param>
 /// <param name="context">The execution context in which the code that manages the newly created object will run. </param>
 /// <param name="activationParams">Use <see cref="IntPtr.Zero"/> as the default value. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd371405%28v=vs.85%29.aspx for more details.</param>
 /// <returns>A pointer variable into which the method writes the address of the interface specified by parameter <paramref name="iid"/>.</returns>
 public IntPtr Activate(Guid iid, CLSCTX context, IntPtr activationParams)
 {
     IntPtr ptr;
     CoreAudioAPIException.Try(ActivateNative(iid, context, activationParams, out ptr), InterfaceName, "Activate");
     return ptr;
 }
示例#3
0
 public object CreateClassFactory(CLSCTX dwContext, string server)
 {
     return(COMUtilities.CreateClassFactory(Clsid, COMInterfaceEntry.IID_IUnknown, dwContext, server));
 }
示例#4
0
		public static extern HResult CoCreateInstance(Guid rclsid, IntPtr pUnkOuter, CLSCTX dwClsContext, Guid riid, out IntPtr ppv);
示例#5
0
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            object result = null;
            Guid   incomingTransactionID = Guid.Empty;

            if (ContextUtil.IsInTransaction)
            {
                incomingTransactionID = ContextUtil.TransactionId;
            }
            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInstanceCreationRequest,
                                               SR.TraceCodeComIntegrationInstanceCreationRequest, this.info, message, incomingTransactionID);

            WindowsIdentity callerIdentity = null;

            callerIdentity = MessageUtil.GetMessageIdentity(message);
            WindowsImpersonationContext impersonateContext = null;

            try
            {
                try
                {
                    if (this.info.HostingMode ==
                        HostingMode.WebHostOutOfProcess)
                    {
                        if (SecurityUtils.IsAtleastImpersonationToken(new SafeCloseHandle(callerIdentity.Token, false)))
                        {
                            impersonateContext = callerIdentity.Impersonate();
                        }
                        else
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.BadImpersonationLevelForOutOfProcWas), HR.ERROR_BAD_IMPERSONATION_LEVEL));
                        }
                    }

                    CLSCTX clsctx = CLSCTX.SERVER;
                    if (PlatformSupportsBitness && (this.info.HostingMode ==
                                                    HostingMode.WebHostOutOfProcess))
                    {
                        if (this.info.Bitness == Bitness.Bitness32)
                        {
                            clsctx |= CLSCTX.ACTIVATE_32_BIT_SERVER;
                        }
                        else
                        {
                            clsctx |= CLSCTX.ACTIVATE_64_BIT_SERVER;
                        }
                    }

                    result = SafeNativeMethods.CoCreateInstance(
                        info.Clsid,
                        null,
                        clsctx,
                        IID_IUnknown);
                }
                finally
                {
                    if (impersonateContext != null)
                    {
                        impersonateContext.Undo();
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                Uri from = null;
                if (message.Headers.From != null)
                {
                    from = message.Headers.From.Uri;
                }

                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusInstanceCreationError,
                                                    from == null ? string.Empty : from.ToString(),
                                                    this.info.AppID.ToString(),
                                                    this.info.Clsid.ToString(),
                                                    incomingTransactionID.ToString(),
                                                    callerIdentity.Name,
                                                    e.ToString());

                throw TraceUtility.ThrowHelperError(e, message);
            }


            TransactionProxy proxy = instanceContext.Extensions.Find <TransactionProxy>();

            if (proxy != null)
            {
                proxy.InstanceID = result.GetHashCode();
            }

            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInstanceCreationSuccess,
                                               SR.TraceCodeComIntegrationInstanceCreationSuccess, this.info, message, result.GetHashCode(), incomingTransactionID);
            return(result);
        }
 public object CreateInstanceAsObject(CLSCTX dwContext, string server)
 {
     return(CreateInstance(server, false));
 }
示例#7
0
 static extern object CoCreateInstance(
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
    [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
    CLSCTX dwClsContext,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);
 private COMEnumerateInterfaces(Guid clsid, CLSCTX clsctx, List<COMInterfaceInstance> interfaces, List<COMInterfaceInstance> factory_interfaces)
 {
     _interfaces = interfaces;
     _factory_interfaces = factory_interfaces;
     _clsid = clsid;
     _clsctx = clsctx;
 }
示例#9
0
 static extern void CoCreateInstanceEx(
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
    [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
    CLSCTX dwClsCtx,
    COSERVERINFO pServerInfo,
    uint cmq,
    [In, Out] MULTI_QI[] pResults);
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            object obj2  = null;
            Guid   empty = Guid.Empty;

            if (ContextUtil.IsInTransaction)
            {
                empty = ContextUtil.TransactionId;
            }
            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, 0x50012, "TraceCodeComIntegrationInstanceCreationRequest", this.info, message, empty);
            WindowsIdentity messageIdentity = null;

            messageIdentity = MessageUtil.GetMessageIdentity(message);
            WindowsImpersonationContext context = null;

            try
            {
                try
                {
                    if (this.info.HostingMode == HostingMode.WebHostOutOfProcess)
                    {
                        if (!System.ServiceModel.ComIntegration.SecurityUtils.IsAtleastImpersonationToken(new SafeCloseHandle(messageIdentity.Token, false)))
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(System.ServiceModel.SR.GetString("BadImpersonationLevelForOutOfProcWas"), HR.ERROR_BAD_IMPERSONATION_LEVEL));
                        }
                        context = messageIdentity.Impersonate();
                    }
                    CLSCTX sERVER = CLSCTX.SERVER;
                    if (PlatformSupportsBitness && (this.info.HostingMode == HostingMode.WebHostOutOfProcess))
                    {
                        if (this.info.Bitness == Bitness.Bitness32)
                        {
                            sERVER |= CLSCTX.ACTIVATE_32_BIT_SERVER;
                        }
                        else
                        {
                            sERVER |= CLSCTX.ACTIVATE_64_BIT_SERVER;
                        }
                    }
                    obj2 = System.ServiceModel.ComIntegration.SafeNativeMethods.CoCreateInstance(this.info.Clsid, null, sERVER, IID_IUnknown);
                }
                finally
                {
                    if (context != null)
                    {
                        context.Undo();
                    }
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                Uri uri = null;
                if (message.Headers.From != null)
                {
                    uri = message.Headers.From.Uri;
                }
                System.ServiceModel.DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.ComPlus, (EventLogEventId)(-1073610726), new string[] { (uri == null) ? string.Empty : uri.ToString(), this.info.AppID.ToString(), this.info.Clsid.ToString(), empty.ToString(), messageIdentity.Name, exception.ToString() });
                throw TraceUtility.ThrowHelperError(exception, message);
            }
            System.ServiceModel.ComIntegration.TransactionProxy proxy = instanceContext.Extensions.Find <System.ServiceModel.ComIntegration.TransactionProxy>();
            if (proxy != null)
            {
                proxy.InstanceID = obj2.GetHashCode();
            }
            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, 0x50013, "TraceCodeComIntegrationInstanceCreationSuccess", this.info, message, obj2.GetHashCode(), empty);
            return(obj2);
        }
示例#11
0
 private static extern Result CoCreateInstanceFromApp([In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
                                                      IntPtr pUnkOuter,
                                                      CLSCTX dwClsContext,
                                                      IntPtr reserved,
                                                      int countMultiQuery,
                                                      ref MultiQueryInterface query);
示例#12
0
 private static extern int CoCreateInstance(ref Guid clsid, IntPtr pUnkOuter, CLSCTX dwClsContext, ref Guid iid, out IntPtr ptrIf);
示例#13
0
 /// <summary>Initializes a new instance of the <see cref="ComClassFactory"/> class.</summary>
 /// <param name="punkObject">The COM object that is to be registered as a class object and queried for interfaces.</param>
 /// <param name="classContext">The context within which the COM object is to be run.</param>
 /// <param name="classUse">Indicates how connections are made to the class object.</param>
 public ComClassFactory(IComObject punkObject, CLSCTX classContext, REGCLS classUse)
 {
     comObj = punkObject ?? throw new ArgumentNullException(nameof(punkObject));
     CoRegisterClassObject(comObj.GetType().CLSID(), this, classContext, classUse, out registrationId).ThrowIfFailed();
 }
 public static extern HRESULT CoCreateInstance(
     ref Guid rclsid,
     IntPtr punkOuter,
     CLSCTX dwClsContext,
     ref Guid riid,
     [MarshalAs(UnmanagedType.Interface)] out object ppv);
示例#15
0
 public static extern void CoCreateInstance(
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
    [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
    CLSCTX dwClsContext,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid,
    [MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject);
示例#16
0
 public static extern int CoRegisterClassObject(
     ref Guid rclsid,
     [MarshalAs(UnmanagedType.Interface)] IClassFactory pUnk,
     CLSCTX dwClsContext,
     REGCLS flags,
     out uint lpdwRegister);
示例#17
0
 static extern void CoGetInstanceFromFile(
             COSERVERINFO pServerInfo,
             ref Guid pClsid,
             [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
             CLSCTX dwClsCtx,
             STGM grfMode,
             string pwszName,
             uint cmq,
             [In, Out] MULTI_QI[] rgmqResults);
示例#18
0
 internal static extern HResult CoCreateInstance([MarshalAs(UnmanagedType.LPStruct)] [In] Guid rclsid, IntPtr pUnkOuter, CLSCTX dwClsContext, [MarshalAs(UnmanagedType.LPStruct)] [In] Guid riid, out IntPtr comObject);
示例#19
0
 static extern void CoGetInstanceFromIStorage(COSERVERINFO pServerInfo, ref Guid pclsid,
    [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, CLSCTX dwClsCtx,
    IStorage pstg, uint cmq, [In, Out] MULTI_QI[] rgmqResults);
 internal static extern int CoCreateInstanceEx([In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
                                               [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
                                               CLSCTX dwClsCtx,
                                               IntPtr pServerInfo,
                                               uint cmq,
                                               [In, Out] MULTI_QI[] pResults);
示例#21
0
 public static extern int CoCreateInstance(
     ref Guid rclsid,
     IntPtr pUnkOuter,
     CLSCTX dwClsContext,
     ref Guid riid,
     out IntPtr ppv);
示例#22
0
 public object CreateClassFactory(CLSCTX dwContext, string server)
 {
     return(CreateInstance(server, true));
 }
示例#23
0
 public static extern object CoGetClassObject(
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
     CLSCTX dwClsContext,
     IntPtr pServerInfo,
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);
示例#24
0
 public static extern uint CoCreateInstance(
     [In] ref Guid rclsid,
     IntPtr pUnkOuter,
     [MarshalAs(UnmanagedType.I4)] CLSCTX dwClsContext,
     [In] ref Guid riid,
     [Out] out IntPtr ppv);
示例#25
0
 public static extern HRESULT CoGetClassObject(
     ref Guid rclsid,
     CLSCTX dwContext,
     IntPtr pvReserved,
     ref Guid riid,
     [MarshalAs(UnmanagedType.Interface)] out IClassFactory2 ppv);
示例#26
0
 public static extern object CoCreateInstance(
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
     [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
     CLSCTX dwClsContext,
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);
示例#27
0
        public IntPtr CreateInstance(CLSCTX dwContext, string server)
        {
            IntPtr pInterface = IntPtr.Zero;

            if (dwContext == CLSCTX.ALL)
            {
                if (DefaultServerType == COMServerType.InProcServer32)
                {
                    dwContext = CLSCTX.INPROC_SERVER;
                }
                else if (DefaultServerType == COMServerType.LocalServer32)
                {
                    dwContext = CLSCTX.LOCAL_SERVER;
                }
                else if (DefaultServerType == COMServerType.InProcHandler32)
                {
                    dwContext = CLSCTX.INPROC_HANDLER;
                }
                else
                {
                    dwContext = CLSCTX.SERVER;
                }
            }

            Guid iid   = COMInterfaceEntry.CreateKnownInterface(COMInterfaceEntry.KnownInterfaces.IUnknown).Iid;
            Guid clsid = Clsid;

            int hr = 0;

            if (server != null)
            {
                MULTI_QI[] qis = new MULTI_QI[1];
                qis[0] = new MULTI_QI(iid);
                COSERVERINFO server_info = new COSERVERINFO(server);
                try
                {
                    hr = COMUtilities.CoCreateInstanceEx(ref clsid, IntPtr.Zero, dwContext, server_info, 1, qis);
                    if (hr == 0)
                    {
                        hr = qis[0].HResult();
                        if (hr == 0)
                        {
                            pInterface = qis[0].GetObjectPointer();
                        }
                    }
                }
                finally
                {
                    ((IDisposable)qis[0]).Dispose();
                }
            }
            else
            {
                hr = COMUtilities.CoCreateInstance(ref clsid, IntPtr.Zero, dwContext, ref iid, out pInterface);
            }

            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            return(pInterface);
        }
示例#28
0
 /// <summary>
 /// Creates a COM object with the specified interface.
 /// </summary>
 /// <param name="iid">The interface identifier. This parameter is a reference to a GUID that identifies the interface that the caller requests be activated. The caller will use this interface to communicate with the COM object.</param>
 /// <param name="context">The execution context in which the code that manages the newly created object will run. </param>
 /// <param name="activationParams">Use <see cref="IntPtr.Zero"/> as the default value. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd371405%28v=vs.85%29.aspx for more details.</param>
 /// <param name="pinterface">A pointer variable into which the method writes the address of the interface specified by parameter <paramref name="iid"/>.</param>
 /// <returns>HRESULT</returns>
 public unsafe int ActivateNative(Guid iid, CLSCTX context, IntPtr activationParams, out IntPtr pinterface)
 {
     pinterface = IntPtr.Zero;
     fixed (void* ppinterface = &pinterface)
     {
         var result = InteropCalls.CallI(UnsafeBasePtr, &iid, (uint) context, activationParams,
             new IntPtr(ppinterface), ((void**) (*(void**) UnsafeBasePtr))[3]);
         return result;
     }
 }
示例#29
0
        private void GetInterfacesInternal(NtToken token)
        {
            IntPtr punk         = IntPtr.Zero;
            IntPtr pfactory     = IntPtr.Zero;
            Guid   IID_IUnknown = COMInterfaceEntry.IID_IUnknown;
            CLSCTX clsctx       = _clsctx;

            if (token != null)
            {
                clsctx |= CLSCTX.ENABLE_CLOAKING;
            }

            using (var imp = token?.Impersonate())
            {
                int hr = 0;
                if (_winrt_component)
                {
                    hr = COMUtilities.RoGetActivationFactory(_activatable_classid, ref IID_IUnknown, out pfactory);
                }
                else
                {
                    hr = COMUtilities.CoGetClassObject(ref _clsid, clsctx, null, ref IID_IUnknown, out pfactory);
                }
                // If we can't get class object, no chance we'll get object.
                if (hr != 0)
                {
                    throw new Win32Exception(hr);
                }

                if (_winrt_component)
                {
                    hr = COMUtilities.RoActivateInstance(_activatable_classid, out punk);
                }
                else
                {
                    hr = COMUtilities.CoCreateInstance(ref _clsid, IntPtr.Zero, clsctx,
                                                       ref IID_IUnknown, out punk);
                }
                if (hr != 0)
                {
                    punk = IntPtr.Zero;
                }

                try
                {
                    Guid[] additional_iids = new[] {
                        COMInterfaceEntry.IID_IMarshal,
                        COMInterfaceEntry.IID_IPSFactoryBuffer,
                        COMInterfaceEntry.IID_IStdMarshalInfo,
                        COMInterfaceEntry.IID_IMarshal2
                    };

                    Dictionary <IntPtr, string> module_names = new Dictionary <IntPtr, string>();
                    foreach (var iid in additional_iids)
                    {
                        QueryInterface(punk, iid, module_names, _interfaces);
                        QueryInterface(pfactory, iid, module_names, _factory_interfaces);
                    }

                    var actctx = ActivationContext.FromProcess();
                    if (actctx != null)
                    {
                        foreach (var intf in actctx.ComInterfaces)
                        {
                            QueryInterface(punk, intf.Iid, module_names, _interfaces);
                            QueryInterface(pfactory, intf.Iid, module_names, _factory_interfaces);
                        }
                    }

                    using (RegistryKey interface_key = Registry.ClassesRoot.OpenSubKey("Interface"))
                    {
                        foreach (string iid_string in interface_key.GetSubKeyNames())
                        {
                            if (Guid.TryParse(iid_string, out Guid iid))
                            {
                                QueryInterface(punk, iid, module_names, _interfaces);
                                QueryInterface(pfactory, iid, module_names, _factory_interfaces);
                            }
                        }
                    }

                    QueryInspectableInterfaces(punk, module_names, _interfaces);
                    QueryInspectableInterfaces(pfactory, module_names, _factory_interfaces);
                }
                finally
                {
                    if (pfactory != IntPtr.Zero)
                    {
                        Marshal.Release(pfactory);
                    }

                    if (punk != IntPtr.Zero)
                    {
                        Marshal.Release(punk);
                    }
                }
            }
        }
示例#30
0
 public COMEnumerateInterfaces(Guid clsid, CLSCTX clsctx, string activatable_classid, bool sta, int timeout, NtToken token)
     : this(clsid, clsctx, activatable_classid, new List <COMInterfaceInstance>(), new List <COMInterfaceInstance>())
 {
     GetInterfaces(sta, timeout, token);
 }
 public static extern int CoRegisterClassObject(
     ref Guid rclsid,
     [MarshalAs(UnmanagedType.Interface)] IClassFactory pUnk,
     CLSCTX dwClsContext,
     REGCLS flags,
     out uint lpdwRegister);
示例#32
0
 public static extern object CoGetClassObject(
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
    CLSCTX dwClsContext,
    IntPtr pServerInfo,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);
示例#33
0
 /// <summary>Initializes a new instance of the <see cref="ShellExecuteCommand"/> class.</summary>
 /// <param name="classContext">The context within which the COM object is to be run.</param>
 /// <param name="classUse">Indicates how connections are made to the class object.</param>
 protected ShellExecuteCommand(CLSCTX classContext, REGCLS classUse) : base(classContext, classUse)
 {
 }
 public COMEnumerateInterfaces(Guid clsid, CLSCTX clsctx, bool sta, int timeout) 
     : this(clsid, clsctx, new List<COMInterfaceInstance>(), new List<COMInterfaceInstance>())
 {
     GetInterfaces(sta, timeout);
 }
示例#35
0
 public static extern int CoGetInstanceFromIStorage(COSERVERINFO pServerInfo, ref Guid pclsid,
                                                    [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, CLSCTX dwClsCtx,
                                                    IStorage pstg, uint cmq, [In, Out] MULTI_QI[] rgmqResults);
示例#36
0
 public static extern int CoGetClassObject(ref Guid rclsid, CLSCTX dwClsContext, IntPtr pServerInfo, ref Guid riid, out IntPtr ppv);
示例#37
0
 internal static extern HResult CoCreateInstance([MarshalAs(UnmanagedType.LPStruct)][In] Guid rclsid, IntPtr pUnkOuter, CLSCTX dwClsContext, [MarshalAs(UnmanagedType.LPStruct)][In] Guid riid, out IntPtr comObject);
示例#38
0
	private static extern int CoCreateInstance(	ref Guid clsid, IntPtr pUnkOuter, CLSCTX dwClsContext, ref Guid iid, out IntPtr ptrIf );
示例#39
0
 public COMEnumerateInterfaces(Guid clsid, CLSCTX clsctx, bool sta, int timeout)
     : this(clsid, clsctx, new List <COMInterfaceInstance>(), new List <COMInterfaceInstance>())
 {
     GetInterfaces(sta, timeout);
 }
 public static extern int CoCreateInstance(ref Guid rclsid, IntPtr pUnkOuter, CLSCTX dwClsContext, ref Guid riid, out IntPtr ppv);
示例#41
0
        public async Task CreateInstanceFromCLSID(Guid clsid, CLSCTX clsctx, bool class_factory)
        {
            try
            {
                COMCLSIDEntry ent = null;
                Dictionary <string, string> props = new Dictionary <string, string>();
                object comObj     = null;
                string strObjName = "";
                IEnumerable <COMInterfaceEntry> ints = null;

                if (m_registry.Clsids.ContainsKey(clsid))
                {
                    ent        = m_registry.Clsids[clsid];
                    strObjName = ent.Name;
                    props.Add("CLSID", ent.Clsid.FormatGuid());
                    props.Add("Name", ent.Name);
                    props.Add("Server", ent.DefaultServer);
                    await ent.LoadSupportedInterfacesAsync(false);

                    if (class_factory)
                    {
                        comObj = ent.CreateClassFactory();
                        ints   = ent.FactoryInterfaces.Select(i => m_registry.MapIidToInterface(i.Iid));
                    }
                    else
                    {
                        comObj = ent.CreateInstanceAsObject(clsctx, null);
                        ints   = ent.Interfaces.Select(i => m_registry.MapIidToInterface(i.Iid));
                    }
                }
                else
                {
                    Guid   unk = COMInterfaceEntry.IID_IUnknown;
                    IntPtr pObj;
                    int    hr;

                    if (class_factory)
                    {
                        hr = COMUtilities.CoGetClassObject(ref clsid, clsctx, null, ref unk, out pObj);
                    }
                    else
                    {
                        hr = COMUtilities.CoCreateInstance(ref clsid, IntPtr.Zero, clsctx,
                                                           ref unk, out pObj);
                    }

                    if (hr != 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    try
                    {
                        ints       = m_registry.GetInterfacesForIUnknown(pObj).ToArray();
                        comObj     = Marshal.GetObjectForIUnknown(pObj);
                        strObjName = clsid.FormatGuid();
                        props.Add("CLSID", clsid.FormatGuid());
                    }
                    finally
                    {
                        Marshal.Release(pObj);
                    }
                }

                if (comObj != null)
                {
                    /* Need to implement a type library reader */
                    Type dispType = COMUtilities.GetDispatchTypeInfo(this, comObj);

                    HostControl(new ObjectInformation(m_registry, ent, strObjName, comObj, props, ints.ToArray()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }