BHO Project (class library) add a reference to two Com//microsoft HTML Object Library, Microsoft Internet controls;using System.Runtime.InteropServices ; namespace testbho{ [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);} }
Using microsoft.win32;using mshtml;using shdocvw;namespace testbh{//each open IE Browser option page will create an instance of the Mybho class to correspond to the IE Options page//ie8 is each TA b A standalone process that, when the tab process of IE is created, creates an instance of the Mybho class [ComVisible (True), a Guid ("8A194578-81EA-4850-9911-13BA2D71EFBD"), ClassInterface (ClassInterfaceType.None)] public class Mybho:iobjectwithsite {InternetExplorer ie; Frmbho frm; Logs Logs = new Logs (); public int SetSite (object site) {if (site! = null) {ie = (InternetExplorer) s Ite Logs. ADD ("bho Build"); Ie. DocumentComplete + = new Dwebbrowserevents2_documentcompleteeventhandler (ie_documentcomplete); } else {ie. DocumentComplete-= new Dwebbrowserevents2_documentcompleteeventhandler (ie_documentcomplete); } return 0; } private void Ie_documentcomplete (object pdisp, ref object URL) {if (URL. ToString (). StartsWith ("Http://116.252.254.204:8001/")) {logs. ADD (URL. ToString ()); Logs. ADD ("-----------------------------------------"); Logs. Add (ie. Locationurl); Logs. Add (ie. LocationName); Logs. Add (ie. Name); Logs. ADD ("-----------------------------------------"); if (frm==null) frm = new frmbho (logs); frm. Show (); frm. Showtext (); }} public int getsite (ref GUID GUID, out IntPtr ppvsite) {IntPtr punk = Marshal.getiunkn Ownforobject (IE); int hr = Marshal.queryinterface (punk, ref GUID, out ppvsite); Marshal.release (Punk); return HR; } #region register bho public static string key = "Software\\microsoft\\windows\\currentversion\\explorer\\browser Helper Objects "; [comregisterfunction] public static void Registerbho (type type) {RegistryKey RegistryKey = RegisTry. Localmachine.opensubkey (key, true); if (RegistryKey = = null) RegistryKey = Registry.LocalMachine.CreateSubKey (key); String guid = type. Guid. ToString ("B"); RegistryKey Ourkey = Registrykey.opensubkey (GUID); if (Ourkey = = null) Ourkey = Registrykey.createsubkey (GUID); Registrykey.close (); Ourkey.close (); } [comunregisterfunction] public static void Unregisterbho (type type) {RegistryKey regist Rykey = Registry.LocalMachine.OpenSubKey (key, true); String guid = type. Guid. ToString ("B"); if (RegistryKey! = null) Registrykey.deletesubkey (GUID, false); } #endregion}
IE plugin bho