自己照着网上的文档做了个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);
}
}
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
...