首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

bho注册有关问题

2012-06-21 
bho注册问题自己照着网上的文档做了个bho,注册的时候一直出现这个问题类型“bho”具有多个COM注册函数代码如

bho注册问题
自己照着网上的文档做了个bho,注册的时候一直出现这个问题
类型“bho”具有多个COM注册函数

代码如下

C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using SHDocVw;using mshtml;using System.Runtime.InteropServices;using Microsoft.Win32;namespace BHO_Gyc.BHO{        [               ComVisible(true),             Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),            ClassInterface(ClassInterfaceType.None)        ]    public class BHO:IObjectWithSite    {        WebBrowser webBrowser;        HTMLDocument document;     public void OnDocumentComplete(object pDisp,ref object URL)     {         //string url = URL as string;         //object anObject = new object();         //if (url.IndexOf("about:blank") >= 0)         //{         //    return;         //}         //if (url.IndexOf("baidu.com") >= 0)         //{         //    webBrowser.Navigate("http://www.sohu.com", ref anObject, ref anObject, ref anObject, ref anObject);         //}         try         {             document = (HTMLDocument)webBrowser.Document;             foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT"))             {                 System.Windows.Forms.MessageBox.Show(tempElement.name != null ? tempElement.name : "it sucks,no name,try id" + ((IHTMLElement)tempElement).id);             }         }         catch(Exception e)         {             System.Windows.Forms.MessageBox.Show(e.Message);         }     }     public int SetSite(object site)     {         if (site != null)         {             webBrowser = (WebBrowser)site;             webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);         }         else         {             webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);             webBrowser = null;         }         return 0;     }     public int GetSite(ref Guid guid, out IntPtr ppvsite)     {         IntPtr punk = Marshal.GetIUnknownForObject(webBrowser);         int hr = Marshal.QueryInterface(punk, ref guid, out ppvsite);         Marshal.Release(punk);         return hr;     }     public static string BHOKEYNAME = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";     [ComRegisterFunction]     public static void RegisterBHO(Type type)     {         try         {             RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);             if (registryKey == null)             {                 registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);             }             string guid = type.GUID.ToString("B");             RegistryKey ourkey = registryKey.OpenSubKey(guid);             if (ourkey == null)             {                 ourkey = registryKey.CreateSubKey(guid);             }             ourkey.SetValue("Alright", 1);             registryKey.Close();             ourkey.Close();         }         catch (Exception e)         {             System.Windows.Forms.MessageBox.Show(e.Message+"1");         }     }     [ComRegisterFunction]     public static void UnregisterBHO(Type type)     {         RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);         string guid = type.GUID.ToString("B");         if (registryKey != null)         {             registryKey.DeleteSubKey(guid,false);         }     }    }}

C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;namespace BHO_Gyc{    [           ComVisible(true),           InterfaceType(ComInterfaceType.InterfaceIsIUnknown),           Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")       ]    public interface IObjectWithSite    {        [PreserveSig]        int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);        [PreserveSig]        int GetSite(ref Guid guid, out IntPtr ppvsite);    }} 



[解决办法]
写错了吧...
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
...

热点排行