GetDispatchTypeInfo() public static méthode

public static GetDispatchTypeInfo ( object comObj ) : Type
comObj object
Résultat System.Type
Exemple #1
0
        private async void OpenObjectInformation(object comObj, string defaultName)
        {
            if (comObj != null)
            {
                Dictionary <string, string> props = new Dictionary <string, string>();
                string strObjName = "";
                IEnumerable <COMInterfaceEntry> ints = null;
                Guid clsid = COMUtilities.GetObjectClass(comObj);

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

                    ints = ent.Interfaces.Select(i => m_registry.MapIidToInterface(i.Iid));
                }
                else
                {
                    ints       = m_registry.GetInterfacesForObject(comObj);
                    strObjName = defaultName != null ? defaultName : clsid.ToString("B");
                    props.Add("CLSID", clsid.ToString("B"));
                }

                Type dispType = COMUtilities.GetDispatchTypeInfo(comObj);
                HostControl(new ObjectInformation(m_registry, strObjName, comObj, props, ints.ToArray()));
            }
        }
Exemple #2
0
        private void menuROTBindToObject_Click(object sender, EventArgs e)
        {
            if (listViewROT.SelectedItems.Count != 0)
            {
                MonikerInfo info = (MonikerInfo)(listViewROT.SelectedItems[0].Tag);

                Dictionary <string, string> props = new Dictionary <string, string>();
                props.Add("Display Name", info.strDisplayName);
                props.Add("CLSID", info.clsid.FormatGuid());

                try
                {
                    IBindCtx bindCtx = COMUtilities.CreateBindCtx(0);
                    Guid     unk     = COMInterfaceEntry.IID_IUnknown;
                    object   comObj;
                    Type     dispType;

                    info.moniker.BindToObject(bindCtx, null, ref unk, out comObj);
                    dispType = COMUtilities.GetDispatchTypeInfo(this, comObj);
                    ObjectInformation view = new ObjectInformation(m_registry, null, info.strDisplayName,
                                                                   comObj, props, m_registry.GetInterfacesForObject(comObj));
                    Program.GetMainForm(m_registry).HostControl(view);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #3
0
        public async Task HostObject(ICOMClassEntry ent, object obj, bool factory)
        {
            Dictionary <string, string> props = new Dictionary <string, string>();

            if (ent == null)
            {
                ent = new COMCLSIDEntry(m_registry, Guid.Empty, COMServerType.UnknownServer);
            }
            props.Add("CLSID", ent.Clsid.FormatGuid());
            props.Add("Name", ent.Name);
            props.Add("Server", ent.DefaultServer);

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

            if (!ent.InterfacesLoaded)
            {
                await ent.LoadSupportedInterfacesAsync(false, null);
            }

            IEnumerable <COMInterfaceInstance> intfs = factory ? ent.FactoryInterfaces : ent.Interfaces;

            ObjectInformation view = new ObjectInformation(m_registry, ent, ent.Name, obj,
                                                           props, intfs.Select(i => m_registry.MapIidToInterface(i.Iid)).ToArray());

            HostControl(view);
        }
Exemple #4
0
        private void btnDispatch_Click(object sender, EventArgs e)
        {
            Control frm = new TypedObjectViewer(m_registry, m_objName, m_pEntry, COMUtilities.GetDispatchTypeInfo(m_pObject));;

            if ((frm != null) && !frm.IsDisposed)
            {
                Program.GetMainForm().HostControl(frm);
            }
        }
Exemple #5
0
        private async void menuViewCreateInstanceFromCLSID_Click(object sender, EventArgs e)
        {
            using (CreateCLSIDForm frm = new CreateCLSIDForm())
            {
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        Guid g = frm.Clsid;
                        Dictionary <string, string> props = new Dictionary <string, string>();
                        object comObj     = null;
                        string strObjName = "";
                        IEnumerable <COMInterfaceEntry> ints = null;

                        if (m_registry.Clsids.ContainsKey(g))
                        {
                            COMCLSIDEntry ent = m_registry.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(frm.ClsCtx);
                            await ent.LoadSupportedInterfacesAsync(false);
                        }
                        else
                        {
                            Guid   unk = COMInterfaceEntry.IID_IUnknown;
                            IntPtr pObj;

                            if (COMUtilities.CoCreateInstance(ref g, IntPtr.Zero, frm.ClsCtx,
                                                              ref unk, out pObj) == 0)
                            {
                                ints       = m_registry.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);

                            HostControl(new ObjectInformation(m_registry, strObjName, comObj, props, ints.ToArray()));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        private void btnDispatch_Click(object sender, EventArgs e)
        {
            Type disp_type = COMUtilities.GetDispatchTypeInfo(this, m_pObject);

            if (disp_type != null)
            {
                Control frm = new TypedObjectViewer(m_registry, m_objName, m_pEntry, disp_type);
                if ((frm != null) && !frm.IsDisposed)
                {
                    EntryPoint.GetMainForm(m_registry).HostControl(frm);
                }
            }
        }
        private async 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 = m_reg.MapClsidToEntry(((COMProgIDEntry)node.Tag).Clsid);
                }

                if (ent != null)
                {
                    Dictionary <string, string> props = new Dictionary <string, string>();
                    try
                    {
                        object comObj = ent.CreateInstanceAsObject(CLSCTX.CLSCTX_ALL);
                        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);

                            await ent.LoadSupportedInterfacesAsync(false);

                            ObjectInformation view = new ObjectInformation(m_reg, ent.Name, comObj,
                                                                           props, ent.Interfaces.Select(i => m_reg.MapIidToInterface(i.Iid)).ToArray());
                            Program.GetMainForm().HostControl(view);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemple #8
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, null);

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