下面是c#写的一个BHO程序,我注册了dll后,怎么样才能打开IE让程序有反应啊using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using SHDocVw;
using mshtml;
using Microsoft.Win32;namespace testbho {
[ComVisible(true),
Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
ClassInterface(ClassInterfaceType.None)
]
public class BHO:IObjectWithSite {
WebBrowser webbrower;
HTMLDocument document;
public void OnDocumentComplete(object pdisp,ref object URL) {
try {
document = (HTMLDocument)webbrower.Document;
foreach (IHTMLInputElement tempElement in document.getElementsByTagName("Input")) {
System.Windows.Forms.MessageBox.Show(tempElement.name != null?tempElement.name:"it sunks,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) {
webbrower = (WebBrowser)site;
webbrower.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
} else {
webbrower.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
webbrower = null;
}
return 0;
} public int GetSite(ref Guid guid,out IntPtr ppvSite) {
IntPtr punk = Marshal.GetIUnknownForObject(webbrower);
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) {
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(); } }
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using SHDocVw;
using mshtml;
using Microsoft.Win32;namespace testbho {
[ComVisible(true),
Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
ClassInterface(ClassInterfaceType.None)
]
public class BHO:IObjectWithSite {
WebBrowser webbrower;
HTMLDocument document;
public void OnDocumentComplete(object pdisp,ref object URL) {
try {
document = (HTMLDocument)webbrower.Document;
foreach (IHTMLInputElement tempElement in document.getElementsByTagName("Input")) {
System.Windows.Forms.MessageBox.Show(tempElement.name != null?tempElement.name:"it sunks,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) {
webbrower = (WebBrowser)site;
webbrower.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
} else {
webbrower.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
webbrower = null;
}
return 0;
} public int GetSite(ref Guid guid,out IntPtr ppvSite) {
IntPtr punk = Marshal.GetIUnknownForObject(webbrower);
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) {
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(); } }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货