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