Ejemplo n.º 1
0
        /// <summary>
        /// Scans the interfaces for the filter and it's pins and displays them in a Dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _interfacesButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            PropertiesDialog pd = null;

            // are we in modal or non-modal mode
            if (this.Parent is PropertiesDialog)
            {
                pd = new PropertiesDialog((this.Parent as PropertiesDialog).Text + " Interfaces");
            }
            else
            {
                pd = new PropertiesDialog((this.Parent.Parent as DSFilterNodeUI).CaptionText + " Interfaces");
            }

            pd.TextBox.AppendText("Filter Interfaces:\r\n");

            // create the array of assemblie we want to scan interfaces against
            Assembly[] assemblies = new Assembly[2] {
                typeof(IBaseFilter).Assembly, typeof(IMFGetService).Assembly
            };

            // scan the filter's interfaces
            List <InterfacePair> pairs = InterfaceScanner.Scan(assemblies, _filter);

            foreach (InterfacePair p in pairs)
            {
                pd.TextBox.AppendText(p.InterfaceGuid.ToString() + "\t" + p.InterfaceName + "\r\n");
            }

            // scan the pin interfaces
            foreach (Control c in this.TabControl.Controls)
            {
                if (c.Tag is IPin)
                {
                    pd.TextBox.AppendText("\r\n" + c.Text + " Pin Interfaces:\r\n");

                    List <InterfacePair> pinpairs = InterfaceScanner.Scan(assemblies, c.Tag);
                    foreach (InterfacePair p in pinpairs)
                    {
                        pd.TextBox.AppendText(p.InterfaceGuid.ToString() + "\t" + p.InterfaceName + "\r\n");
                    }
                }
            }
            Cursor = Cursors.Default;
            pd.ShowDialog(this.TopLevelControl);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a brute force scan of all interfaces the COM object implements
        /// </summary>
        /// <param name="assembly">optional Assembly to scan against</param>
        /// <param name="o">Object to scan</param>
        /// <returns>List of Pairs of Interface Name/Interface GUID</returns>
        public static List <InterfacePair> Scan(Assembly[] assemblies, object o)
        {
            if (instance == null)
            {
                instance = new InterfaceScanner();
            }

            Dictionary <string, Guid> hash  = new Dictionary <string, Guid>();
            List <InterfacePair>      pairs = new List <InterfacePair>();

            IntPtr ukn = Marshal.GetIUnknownForObject(o);

            foreach (InterfacePair ip in instance._pairs)
            {
                IntPtr iptr = IntPtr.Zero;
                Marshal.QueryInterface(ukn, ref ip.InterfaceGuid, out iptr);
                if (iptr != IntPtr.Zero)
                {
                    hash.Add(ip.InterfaceName, ip.InterfaceGuid);
                    Marshal.Release(iptr);
                }
            }

            // scan against the array assembly if one was given
            if (assemblies != null)
            {
                for (int x = 0; x < assemblies.Length; x++)
                {
                    Type[] asstypes = assemblies[x].GetTypes();
                    for (int i = 0; i < asstypes.Length; i++)
                    {
                        if (asstypes[i].IsInterface)
                        {
                            IntPtr iptr = IntPtr.Zero;
                            Guid   g    = asstypes[i].GUID;
                            Marshal.QueryInterface(ukn, ref g, out iptr);
                            if (iptr != IntPtr.Zero)
                            {
                                if (!hash.ContainsKey(asstypes[i].Name))
                                {
                                    hash.Add(asstypes[i].Name, asstypes[i].GUID);
                                }
                                Marshal.Release(iptr);
                            }
                        }
                    }
                }
            }

            Marshal.Release(ukn);

            // if it's a managed type, get all of it's interfaces also
            if (!o.GetType().IsCOMObject)
            {
                Type[] t = o.GetType().GetInterfaces();
                for (int i = 0; i < t.Length; i++)
                {
                    if (!hash.ContainsKey(t[i].Name))
                    {
                        hash.Add(t[i].Name, t[i].GUID);
                    }
                }
            }

            // flatten the dictionary into a list
            foreach (KeyValuePair <string, Guid> kvp in hash)
            {
                InterfacePair ip = new InterfacePair();
                ip.InterfaceName = kvp.Key;
                ip.InterfaceGuid = kvp.Value;
                pairs.Add(ip);
            }

            return(pairs);
        }