OleViewDotNet.COMRegistry.GetInterfacesForIUnknown C# (CSharp) Method

GetInterfacesForIUnknown() public method

Get the list of supported interfaces from an IUnknown pointer
public GetInterfacesForIUnknown ( IntPtr pObject ) : IEnumerable
pObject System.IntPtr The IUnknown pointer
return IEnumerable
        public IEnumerable<COMInterfaceEntry> GetInterfacesForIUnknown(IntPtr pObject)
        {
            List<COMInterfaceEntry> ents = new List<COMInterfaceEntry>();
            foreach (COMInterfaceEntry intEnt in m_interfacebyname)
            {
                Guid currIID = intEnt.Iid;
                IntPtr pRequested;

                if (Marshal.QueryInterface(pObject, ref currIID, out pRequested) == 0)
                {
                    Marshal.Release(pRequested);
                    ents.Add(intEnt);
                }
            }
            return ents.AsReadOnly();
        }

Usage Example

Ejemplo n.º 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);
                    }
                }
            }
        }
All Usage Examples Of OleViewDotNet.COMRegistry::GetInterfacesForIUnknown