protected override void AttachInterfaces(object nativeActiveXObject)
        {
            base.AttachInterfaces(nativeActiveXObject);
            IOleControl ctl = (IOleControl)ActiveXInstance;

            ctl.OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
        }
Exemplo n.º 2
0
 public void StopParsing()
 {
     try
     {
         //UnAdvice and clean up
         if ((m_WBConnectionPoint != null) && (m_dwCookie > 0))
         {
             m_WBConnectionPoint.Unadvise(m_dwCookie);
         }
         if (m_WBOleObject != null)
         {
             m_WBOleObject.Close((uint)OLEDOVERB.OLECLOSE_NOSAVE);
             m_WBOleObject.SetClientSite(null);
         }
         if (m_pMSHTML != null)
         {
             Marshal.ReleaseComObject(m_pMSHTML);
             m_pMSHTML = null;
         }
         if (m_WBConnectionPoint != null)
         {
             Marshal.ReleaseComObject(m_WBConnectionPoint);
             m_WBConnectionPoint = null;
         }
         if (m_WBOleControl != null)
         {
             Marshal.ReleaseComObject(m_WBOleControl);
             m_WBOleControl = null;
         }
         if (m_WBOleObject != null)
         {
             Marshal.ReleaseComObject(m_WBOleObject);
             m_WBOleObject = null;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        cHTMLParser()
        {
            //Create a new MSHTML, throws exception if fails
            Type htmldoctype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_HTMLDocument, true);
            //Using Activator inplace of CoCreateInstance, returns IUnknown
            //which we cast to a IHtmlDocument2 interface
            m_pMSHTML = (IHTMLDocument2)System.Activator.CreateInstance(htmldoctype);

            //Get the IOleObject
            m_WBOleObject = (IOleObject)m_pMSHTML;
            //Set client site
            int iret = m_WBOleObject.SetClientSite(this);

            //Connect for IPropertyNotifySink
            m_WBOleControl = (IOleControl)m_pMSHTML;
            m_WBOleControl.OnAmbientPropertyChange(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL);

            //Get connectionpointcontainer
            IConnectionPointContainer cpCont = (IConnectionPointContainer)m_pMSHTML;
            cpCont.FindConnectionPoint(ref Iid_Clsids.IID_IPropertyNotifySink, out m_WBConnectionPoint);
            //Advice
            m_WBConnectionPoint.Advise(this, out m_dwCookie);
        }
 public void StopParsing()
 {
     try
     {
         //UnAdvice and clean up
         if ((m_WBConnectionPoint != null) && (m_dwCookie > 0))
             m_WBConnectionPoint.Unadvise(m_dwCookie);
         if (m_WBOleObject != null)
         {
             m_WBOleObject.Close((uint)OLEDOVERB.OLECLOSE_NOSAVE);
             m_WBOleObject.SetClientSite(null);
         }
         if (m_pMSHTML != null)
         {
             Marshal.ReleaseComObject(m_pMSHTML);
             m_pMSHTML = null;
         }
         if (m_WBConnectionPoint != null)
         {
             Marshal.ReleaseComObject(m_WBConnectionPoint);
             m_WBConnectionPoint = null;
         }
         if (m_WBOleControl != null)
         {
             Marshal.ReleaseComObject(m_WBOleControl);
             m_WBOleControl = null;
         }
         if (m_WBOleObject != null)
         {
             Marshal.ReleaseComObject(m_WBOleObject);
             m_WBOleObject = null;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        /// <summary>
        /// Only public method which starts the parsing process
        /// When parsing is done, we receive a DISPID_READYSTATE dispid
        /// in IPropertyNotifySink.OnChanged implementation
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="cookie"></param>
        public void StartParsing(string Url, string cookie)
        {
            IntPtr pUsername = IntPtr.Zero;
            IntPtr pPassword = IntPtr.Zero;
            try
            {
                if (string.IsNullOrEmpty(Url))
                    throw new ApplicationException("Url must have a valid value!");

                //Create a new MSHTML, throws exception if fails
                Type htmldoctype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_HTMLDocument, true);
                //Using Activator inplace of CoCreateInstance, returns IUnknown
                //which we cast to a IHtmlDocument2 interface
                m_pMSHTML = (IHTMLDocument2)System.Activator.CreateInstance(htmldoctype);

                //Get the IOleObject
                m_WBOleObject = (IOleObject)m_pMSHTML;
                //Set client site
                int iret = m_WBOleObject.SetClientSite(this);

                //Connect for IPropertyNotifySink
                m_WBOleControl = (IOleControl)m_pMSHTML;
                m_WBOleControl.OnAmbientPropertyChange(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL);

                //Get connectionpointcontainer
                IConnectionPointContainer cpCont = (IConnectionPointContainer)m_pMSHTML;
                cpCont.FindConnectionPoint(ref Iid_Clsids.IID_IPropertyNotifySink, out m_WBConnectionPoint);
                //Advice
                m_WBConnectionPoint.Advise(this, out m_dwCookie);

                m_Done = false;
                m_Url = Url;

                if (!string.IsNullOrEmpty(cookie))
                    m_pMSHTML.cookie = cookie;

                //Set up username and password if provided
                if (!string.IsNullOrEmpty(m_Username))
                {
                    pUsername = Marshal.StringToCoTaskMemAnsi(m_Username);
                    if (pUsername != IntPtr.Zero)
                        WinApis.InternetSetOption(IntPtr.Zero,
                            InternetSetOptionFlags.INTERNET_OPTION_USERNAME,
                            pUsername, m_Username.Length);
                }
                if (!string.IsNullOrEmpty(m_Password))
                {
                    pPassword = Marshal.StringToCoTaskMemAnsi(m_Password);
                    if (pPassword != IntPtr.Zero)
                        WinApis.InternetSetOption(IntPtr.Zero,
                            InternetSetOptionFlags.INTERNET_OPTION_PASSWORD,
                            pPassword, m_Password.Length);
                }
                //Load
                IPersistMoniker persistMoniker = (IPersistMoniker)m_pMSHTML;
                IMoniker moniker = null;
                WinApis.CreateURLMoniker(null, m_Url, out moniker);
                if (moniker == null)
                    return;
                IBindCtx bindContext = null;
                WinApis.CreateBindCtx((uint)0, out bindContext);
                if (bindContext == null)
                    return;
                persistMoniker.Load(1, moniker, bindContext, 0);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (pUsername != IntPtr.Zero)
                    Marshal.FreeCoTaskMem(pUsername);
                if (pPassword != IntPtr.Zero)
                    Marshal.FreeCoTaskMem(pPassword);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Only public method which starts the parsing process
        /// When parsing is done, we receive a DISPID_READYSTATE dispid
        /// in IPropertyNotifySink.OnChanged implementation
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="cookie"></param>
        public void StartParsing(string Url, string cookie)
        {
            IntPtr pUsername = IntPtr.Zero;
            IntPtr pPassword = IntPtr.Zero;

            try
            {
                if (string.IsNullOrEmpty(Url))
                {
                    throw new ApplicationException("Url must have a valid value!");
                }

                //Create a new MSHTML, throws exception if fails
                Type htmldoctype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_HTMLDocument, true);
                //Using Activator inplace of CoCreateInstance, returns IUnknown
                //which we cast to a IHtmlDocument2 interface
                m_pMSHTML = (IHTMLDocument2)System.Activator.CreateInstance(htmldoctype);

                //Get the IOleObject
                m_WBOleObject = (IOleObject)m_pMSHTML;
                //Set client site
                int iret = m_WBOleObject.SetClientSite(this);

                //Connect for IPropertyNotifySink
                m_WBOleControl = (IOleControl)m_pMSHTML;
                m_WBOleControl.OnAmbientPropertyChange(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL);

                //Get connectionpointcontainer
                IConnectionPointContainer cpCont = (IConnectionPointContainer)m_pMSHTML;
                cpCont.FindConnectionPoint(ref Iid_Clsids.IID_IPropertyNotifySink, out m_WBConnectionPoint);
                //Advice
                m_WBConnectionPoint.Advise(this, out m_dwCookie);

                m_Done = false;
                m_Url  = Url;

                if (!string.IsNullOrEmpty(cookie))
                {
                    m_pMSHTML.cookie = cookie;
                }

                //Set up username and password if provided
                if (!string.IsNullOrEmpty(m_Username))
                {
                    pUsername = Marshal.StringToCoTaskMemAnsi(m_Username);
                    if (pUsername != IntPtr.Zero)
                    {
                        WinApis.InternetSetOption(IntPtr.Zero,
                                                  InternetSetOptionFlags.INTERNET_OPTION_USERNAME,
                                                  pUsername, m_Username.Length);
                    }
                }
                if (!string.IsNullOrEmpty(m_Password))
                {
                    pPassword = Marshal.StringToCoTaskMemAnsi(m_Password);
                    if (pPassword != IntPtr.Zero)
                    {
                        WinApis.InternetSetOption(IntPtr.Zero,
                                                  InternetSetOptionFlags.INTERNET_OPTION_PASSWORD,
                                                  pPassword, m_Password.Length);
                    }
                }
                //Load
                IPersistMoniker persistMoniker = (IPersistMoniker)m_pMSHTML;
                IMoniker        moniker        = null;
                WinApis.CreateURLMoniker(null, m_Url, out moniker);
                if (moniker == null)
                {
                    return;
                }
                IBindCtx bindContext = null;
                WinApis.CreateBindCtx((uint)0, out bindContext);
                if (bindContext == null)
                {
                    return;
                }
                persistMoniker.Load(1, moniker, bindContext, 0);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (pUsername != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pUsername);
                }
                if (pPassword != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pPassword);
                }
            }
        }