自己照着网上的文档做了个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);
}
}
类型“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);
}
}
解决方案 »
- 关于C#发送邮件
- 如何做msdn那样的siteMapPath?
- 江湖救急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!在线等!
- 文件类型问题(*.txvpck)
- 怎样将Datatable中的数据直接导入到Excel模板上
- 急求:模糊查询,关键字查询问题的解决办法
- 请问谁知道"本地连接"的"启用"/"禁用"是修改注册表的哪个项值的?
- === Form 如何实现条件编译?===
- 求助啊,如何调用另台电脑的打印机,按照A电脑样式打印,有图说明
- 高分伺候高人大驾!!!!!!!!---其实问题可能对于你来说,一点都不难!
- 用线程控制控件?
- richtextbox中读数据的问题
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
...