Exemplo n.º 1
0
        private void menuViewCreateInstanceFromCLSID_Click(object sender, EventArgs e)
        {
            GetTextForm frm = new GetTextForm("");
            if (frm.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Guid g = new Guid(frm.Data);
                    Dictionary<string, string> props = new Dictionary<string,string>();
                    object comObj = null;
                    string strObjName = "";
                    COMInterfaceEntry[] ints = null;

                    if (m_comRegistry.Clsids.ContainsKey(g))
                    {
                        COMCLSIDEntry ent = m_comRegistry.Clsids[g];
                        strObjName = ent.Name;
                        props.Add("CLSID", ent.Clsid.ToString("B"));
                        props.Add("Name", ent.Name);
                        props.Add("Server", ent.Server);

                        comObj = ent.CreateInstanceAsObject();
                        ints = m_comRegistry.GetSupportedInterfaces(ent, false);
                    }
                    else
                    {
                        Guid unk = COMInterfaceEntry.IID_IUnknown;
                        IntPtr pObj;

                        if (COMUtilities.CoCreateInstance(ref g, IntPtr.Zero, COMUtilities.CLSCTX.CLSCTX_SERVER,
                            ref unk, out pObj) == 0)
                        {
                            ints = m_comRegistry.GetInterfacesForIUnknown(pObj);
                            comObj = Marshal.GetObjectForIUnknown(pObj);
                            strObjName = g.ToString("B");
                            props.Add("CLSID", g.ToString("B"));
                            Marshal.Release(pObj);
                        }
                    }

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

                        ObjectInformation view = new ObjectInformation(strObjName, comObj, props, ints);
                        view.ShowHint = DockState.Document;
                        view.Show(m_dockPanel);
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        private void createInstanceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = treeComRegistry.SelectedNode;

            if (node != null)
            {
                COMCLSIDEntry ent = null;
                if (node.Tag is COMCLSIDEntry)
                {
                    ent = (COMCLSIDEntry)node.Tag;
                }
                else if (node.Tag is COMProgIDEntry)
                {
                    ent = ((COMProgIDEntry)node.Tag).Entry;
                }

                if(ent != null)
                {
                    Dictionary<string, string> props = new Dictionary<string,string>();
                    try
                    {
                        object comObj = ent.CreateInstanceAsObject();
                        if (comObj != null)
                        {
                            props.Add("CLSID", ent.Clsid.ToString("B"));
                            props.Add("Name", ent.Name);
                            props.Add("Server", ent.Server);

                            /* Need to implement a type library reader */
                            Type dispType = COMUtilities.GetDispatchTypeInfo(comObj);

                            ObjectInformation view = new ObjectInformation(ent.Name, comObj, props, m_reg.GetSupportedInterfaces(ent, false));
                            view.ShowHint = DockState.Document;
                            view.Show(this.DockPanel);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }