예제 #1
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);
                    }
                }
            }
        }
예제 #2
0
 private async void btnCreate_Click(object sender, EventArgs e)
 {
     try
     {
         object comObj = m_clsid.CreateInstanceAsObject(m_clsid.CreateContext, null);
         if (comObj != null)
         {
             await EntryPoint.GetMainForm(m_registry).HostObject(m_clsid, comObj, false);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #3
0
        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);
                    }
                }
            }
        }
예제 #4
0
 private async void menuObjectFromFile_Click(object sender, EventArgs e)
 {
     try
     {
         using (OpenFileDialog dlg = new OpenFileDialog())
         {
             dlg.Filter = "All Files (*.*)|*.*";
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 COMCLSIDEntry entry = m_registry.GetFileClass(dlg.FileName);
                 if (entry != null)
                 {
                     IPersistFile ps = (IPersistFile)entry.CreateInstanceAsObject(entry.CreateContext, null);
                     ps.Load(dlg.FileName, (int)STGM.READ);
                     await HostObject(entry, ps, false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #5
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);
            }
        }