解决方案 »
- C#使用datagirdview查询。
- 怎样将字符串类型的时间“7/1/2011 12:00:00 AM”转换为字符串类型的“20110701”
- 设计员工工资类
- asp.net 中在服务器端就是c#后台程序中,怎样和居于局域网中的com接口进行通讯
- 啊...这个问题太难了,对于我一个新手来说....
- 200分征解--------双窗难题
- VS2008跟VS2005有什么区别?
- 各位高手请进.!! 在IE中使用windows用户控件.
- 请教!
- 进程间通信,使用WM_COPYDATA消息在两个程序间传递字符串,有问题。
- dev中的gridControl分组排序的问题
- 新人求助,希望各路豪杰来帮帮我!
我重新改了下弹出框,加多了输出,然后,测试的时候,是输出下面结果:弹出框 2,6,8,10,11,12,13 这几个弹出框都弹出来,然后, cmd 提示注册成功.C:\Users\Administrator>"C:\Program Files (x86)\Test Program\tools\x86\RegAsm.exe
" /codebase "D:\TestBHO.dll"
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.5420
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can ca
use your assembly to interfere with other applications that may be installed on
the same computer. The /codebase switch is intended to be used only with signed
assemblies. Please give your assembly a strong name and re-register it.
Types registered successfully以下是修改后的代码:public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";[ComRegisterFunction]
public static void RegisterBHO(Type type)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING.2..");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true); if (registryKey == null)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING.4..");
registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
} System.Windows.Forms.MessageBox.Show("BHO TESTING.6.." + BHOKEYNAME); string guid = type.GUID.ToString("B");
RegistryKey ourKey = registryKey.OpenSubKey(guid); System.Windows.Forms.MessageBox.Show("BHO TESTING.8.." + guid); if (ourKey == null)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING.10.." + guid);
ourKey = registryKey.CreateSubKey(guid);
System.Windows.Forms.MessageBox.Show("BHO TESTING.11.." + ourKey);
} ourKey.SetValue("Alright", 1);
System.Windows.Forms.MessageBox.Show("BHO TESTING.12.." + ourKey); registryKey.Close();
ourKey.Close(); System.Windows.Forms.MessageBox.Show("BHO TESTING.13..");
}[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING..3.");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
string guid = type.GUID.ToString("B"); System.Windows.Forms.MessageBox.Show("BHO TESTING.5.." + guid); if (registryKey != null)
{
registryKey.DeleteSubKey(guid, false);
System.Windows.Forms.MessageBox.Show("BHO TESTING.7.." + guid);
}
System.Windows.Forms.MessageBox.Show("BHO TESTING.9.." + guid);
}
然后, 可能是因为注册表的键值也没有, 所以, 当我打开 IE 测试 BHO 的时候, 好像根本就没反应, 下面的代码没有在页面加载完成的时候被调用:没有弹出: System.Windows.Forms.MessageBox.Show("BHO TESTING...");
public class BHO : IObjectWithSite
{
WebBrowser browser;
HTMLDocument document; public void OnDocumentComplete(object pDisp, ref object URL)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING...");
} public int SetSite(object site)
{
if (site != null)
{
browser = (WebBrowser)site;
browser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
}
else
{
browser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
browser = null;
}
return 0;
} public int GetSite(ref Guid guid, out IntPtr ppvSite)
{
IntPtr punk = Marshal.GetIUnknownForObject(browser);
int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
Marshal.Release(punk);
return hr;
}
.....
我重新将上面的 dll 放到 windows server 2003 上面运行, 同样的结果却成功注册与成功在 IE 运行 BHO. 这个问题是与 OS 的版本有关,谢谢.