bho注册问题

joanarc82 2012-06-18 05:03:14
自己照着网上的文档做了个bho,注册的时候一直出现这个问题
类型“bho”具有多个COM注册函数

代码如下
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);
}
}
}
}

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);
}
}
...全文
92 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
joanarc82 2012-06-19
  • 打赏
  • 举报
回复
谢谢,结贴
WAN 2012-06-18
  • 打赏
  • 举报
回复
写错了吧...
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
...
joanarc82 2012-06-18
  • 打赏
  • 举报
回复
坐等坐等坐等坐等

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧