示例#1
0
        internal static void EnumIWebBrowser2Interfaces(IWebBrowser2Processor processor)
        {
            var oc = processor.HTMLDocument() as IOleContainer;

            if (oc == null) return;

            IEnumUnknown eu;
            var hr = oc.EnumObjects(NativeMethods.tagOLECONTF.OLECONTF_EMBEDDINGS, out eu);
            Marshal.ThrowExceptionForHR(hr);

            if (eu == null) return;

            try
            {
                object pUnk;
                int fetched;
                const int MAX_FETCH_COUNT = 1;

                // get the first embedded object
                // pUnk alloc
                hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);
                Marshal.ThrowExceptionForHR(hr);

                while (hr == 0)
                {
                    // Query Interface pUnk for the IWebBrowser2 interface
                    var brow = pUnk as IWebBrowser2;

                    try
                    {
                        if (brow != null)
                        {
                            processor.Process(brow);
                            if (!processor.Continue())
                            {
                                break;
                            }
                            // free brow
                            ReleaseComObjectButIgnoreNull(brow);
                        }
                    }
                    catch
                    {
                        // free brow
                        ReleaseComObjectButIgnoreNull(brow);
                        ReleaseComObjectButIgnoreNull(pUnk);
                    }

                    // pUnk free
                    ReleaseComObjectButIgnoreNull(pUnk);

                    // get the next embedded object
                    // pUnk alloc
                    hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
            finally
            {
                // eu free
                ReleaseComObjectButIgnoreNull(eu);
            }
        }
示例#2
0
        public static void EnumIWebBrowser2Interfaces(IWebBrowser2Processor processor)
        {
            var oc = processor.HTMLDocument() as IOleContainer;

            if (oc == null)
            {
                return;
            }

            IEnumUnknown eu;
            var          hr = oc.EnumObjects(NativeMethods.tagOLECONTF.OLECONTF_EMBEDDINGS, out eu);

            Marshal.ThrowExceptionForHR(hr);

            if (eu == null)
            {
                return;
            }

            try
            {
                object    pUnk;
                int       fetched;
                const int MAX_FETCH_COUNT = 1;

                // get the first embedded object
                // pUnk alloc
                hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);
                Marshal.ThrowExceptionForHR(hr);

                while (hr == 0)
                {
                    // Query Interface pUnk for the IWebBrowser2 interface
                    var brow = pUnk as IWebBrowser2;

                    try
                    {
                        if (brow != null)
                        {
                            processor.Process(brow);
                            if (!processor.Continue())
                            {
                                break;
                            }
                            // free brow
                            ReleaseComObjectButIgnoreNull(brow);
                        }
                    }
                    catch
                    {
                        // free brow
                        ReleaseComObjectButIgnoreNull(brow);
                        ReleaseComObjectButIgnoreNull(pUnk);
                    }

                    // pUnk free
                    ReleaseComObjectButIgnoreNull(pUnk);

                    // get the next embedded object
                    // pUnk alloc
                    hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
            finally
            {
                // eu free
                ReleaseComObjectButIgnoreNull(eu);
            }
        }
示例#3
0
文件: Win32.cs 项目: teknologika/ITiN
        internal static void EnumIWebBrowser2Interfaces(IWebBrowser2Processor processor)
        {
            IEnumUnknown  eu;
            IOleContainer oc = processor.HTMLDocument() as IOleContainer;
            int           hr = oc.EnumObjects(tagOLECONTF.OLECONTF_EMBEDDINGS, out eu);

            Marshal.ThrowExceptionForHR(hr);

            try
            {
                object    pUnk;
                int       fetched;
                const int MAX_FETCH_COUNT = 1;

                // get the first embedded object
                // pUnk alloc
                hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);
                Marshal.ThrowExceptionForHR(hr);

                while (hr == 0)
                {
                    // Query Interface pUnk for the IWebBrowser2 interface
                    IWebBrowser2 brow = pUnk as IWebBrowser2;

                    try
                    {
                        if (brow != null)
                        {
                            processor.Process(brow);
                            if (!processor.Continue())
                            {
                                break;
                            }
                            // free brow
                            Marshal.ReleaseComObject(brow);
                        }
                    }
                    catch
                    {
                        if (brow != null)
                        {
                            // free brow
                            Marshal.ReleaseComObject(brow);
                        }
                        // pUnk free
                        Marshal.ReleaseComObject(pUnk);
                    }

                    // pUnk free
                    Marshal.ReleaseComObject(pUnk);

                    // get the next embedded object
                    // pUnk alloc
                    hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
            finally
            {
                // eu free
                Marshal.ReleaseComObject(eu);
            }
        }