none
使用C# 写BHO, IE 版本为Ie9,问题,多tab时,IE无反应 RRS feed

  • 问题

  • 过程如下:

    regasm注册dll后,打开ie,启动BHO,随意打开一个网页。一切正常。但当我新打开一个tab(about:tab)时整个ie不接受任何消息了。即在新建一个选项卡时,IE不工作。

    此代码为网上找来。能运行

    namespace OGameHelper
    {
        [ComVisible(true)]
        [ClassInterface(ClassInterfaceType.None)]
        // Create a GUID Under Tools\Cteate GUID before compiling
        [Guid("91E08187-00AE-4712-AD3A-6A825FE231BC")]
        public class OGameHelperBHO : IObjectWithSite
        {
            public static readonly Guid IID_IWebBrowserApp = new Guid("{0002DF05-0000-0000-C000-000000000046}");
            public static readonly Guid IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");
    
            private WebBrowserClass explorer;
            private Object site;
    
            public void SetSite(Object newSite)
            {
                if (site != null)
                    Marshal.FinalReleaseComObject(site);
    
                site = newSite;
                if (site != null)
                {
                    IServiceProvider sp = site as IServiceProvider;
    
                    Guid guid = IID_IWebBrowserApp;
                    Guid riid = IID_IUnknown;
    
                    object wba;
                    sp.QueryService(ref guid, ref riid, out wba);
    
                    explorer = (WebBrowserClass)Marshal.CreateWrapperOfType(wba as IWebBrowser, typeof(WebBrowserClass));
    
                    explorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(explorer_DocumentComplete);
                }
                else
                {
                    if (explorer != null)
                    {
                        Marshal.FinalReleaseComObject(explorer);
                        explorer = null;
                    }
                }
            }
    
            private void explorer_DocumentComplete(object pDisp, ref object URL)
            {
    
                MessageBox.Show(URL.ToString());
    
            }
    
            public void GetSite(ref Guid riid, out Object outSite)
            {
                outSite = site;
            }
    
    
            [ComRegisterFunction]
            public static void RegisterBHO(Type t)
            {
                RegistryKey rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects");
                rk.CreateSubKey(t.GUID.ToString("B"));
            }
    
            [ComUnregisterFunction]
            public static void UnregisterBHO(Type t)
            {
                RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects", true);
                rk.DeleteSubKey(t.GUID.ToString("B"));
            }
        }

    2013年6月14日 17:14

答案

全部回复