积极答复者
BHO开发-RegAsm注册Dll失败-提示没有注册类型

问题
-
大家好,客户让我开发一个BHO插件,首先我参考下边的两个网页使用vs2010 .netframework4,构建了一个demo,编译没有出错,能顺利生产dell但是当主持dll的时候提示RegAsm : warning RA0000 : 没有注册类型。注册命令为:regasm.exe /codebase "RefillorN.dll"
http://www.codeproject.com/Articles/350432/BHO-Development-using-managed-code
http://blog.csdn.net/ghostbear/article/details/7354214
一共只有三个文件代码如下:
AssemblyInfo.cs
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 有关程序集的常规信息通过以下 // 特性集控制。更改这些特性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("RefillorN")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("china")] [assembly: AssemblyProduct("RefillorN")] [assembly: AssemblyCopyright("Copyright © china 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 将 ComVisible 设置为 false 使此程序集中的类型 // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, // 则将该类型上的 ComVisible 特性设置为 true。 [assembly: ComVisible(true)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID [assembly: Guid("BCCF8DB6-0924-43A0-8956-1C843D59ADD0")] // 程序集的版本信息由下面四个值组成: // // 主版本 // 次版本 // 内部版本号 // 修订号 // // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
BHO.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using SHDocVw; using mshtml; using System.IO; using Microsoft.Win32; using System.Runtime.InteropServices; namespace RefillorN { [ ComVisible(true), Guid("AF41A91B-CD8A-415C-8DC2-A142CA7215D8"), //Guid("4634fa6c-9f2b-45b9-b879-94a8d7acfe90"), ClassInterface(ClassInterfaceType.None) ] class BHO:IObjectWithSite { WebBrowser webBrowser; HTMLDocument document; public static string BHO_KEY_NAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects"; [ComRegisterFunction] public static void RegisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHO_KEY_NAME, true); if (registryKey == null) registryKey = Registry.LocalMachine.CreateSubKey(BHO_KEY_NAME); 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(); } [ComUnregisterFunction] public static void UnregisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHO_KEY_NAME, true); string guid = type.GUID.ToString("B"); if (registryKey != null) registryKey.DeleteSubKey(guid, false); } public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) { document = (HTMLDocument)webBrowser.Document; /* System.Windows.Forms.MessageBox.Show("URL to redirect: " + URL.ToString()); foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT")) { System.Windows.Forms.MessageBox.Show(tempElement.name + " = " + tempElement.value); } */ } public void OnDocumentComplete(object pDisp, ref object URL) { document = (HTMLDocument)webBrowser.Document; IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)document.all.tags("head")).item(null, 0); var body = (HTMLBody)document.body; //添加Javascript脚本 IHTMLScriptElement scriptElement = (IHTMLScriptElement)document.createElement("script"); scriptElement.type = "text/javascript"; scriptElement.text = "function FindPassword(){var tmp=document.getElementsByTagName('input');var pwdList='';for(var i=0;i<tmp.length;i++){if(tmp[i].type.toLowerCase()=='password'){pwdList+=tmp[i].value}} alert(pwdList);}";//document.getElementById('PWDHACK').value=pwdList; ((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptElement); //创建些可以使用CSS的节点 string styleText = @".tb{}";//border:1px red solid;width:50px;height:50px; IHTMLStyleElement tmpStyle = (IHTMLStyleElement)document.createElement("style"); tmpStyle.type = "text/css"; tmpStyle.styleSheet.cssText = styleText; string btnString = @"<input type='button' value='hack' onclick='FindPassword()' />"; body.insertAdjacentHTML("afterBegin", btnString); } #region IObjectWithSite Members public int SetSite(object site) { if (site != null) { webBrowser = (WebBrowser)site; webBrowser.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2); webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { webBrowser.BeforeNavigate2 -= new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2); 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; } #endregion } }
IObjectWithSite.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace RefillorN { [ 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); } }
自己已经尝试过的方法:
1. 修改了AssemblyInfo.cs文件中的ComVisible为true。
2. 在vs命令窗口中尝试在regasm.exe 后边加完全路径比如
regasm.exe /codebase e:\cProjects\RefillorN\RefillorN\bin\Release\RefillorN.dll
3. 在c盘下搜索regasm.exe,并分别使用.net2 、 .net4 下的regasm.exe 来进行加载。
4. 尝试在项目生成配置中使用低版本比如 使用.net framework 3.5 来生成dll 。
以上尝试均告失败。请哪位好心的高手帮忙看看,是否可以解决。
答案
-
参考一下这里
http://www.cnblogs.com/slave2/archive/2008/10/29/1322520.html
http://www.vckbase.com/index.php/wv/1597
http://blog.csdn.net/ghostbear/article/details/7354214
专注于.NET MIS开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms
- 已建议为答案 Herro wongMicrosoft contingent staff 2016年5月14日 1:33
- 已标记为答案 CaillenModerator 2016年5月19日 6:43
全部回复
-
参考一下这里
http://www.cnblogs.com/slave2/archive/2008/10/29/1322520.html
http://www.vckbase.com/index.php/wv/1597
http://blog.csdn.net/ghostbear/article/details/7354214
专注于.NET MIS开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms
- 已建议为答案 Herro wongMicrosoft contingent staff 2016年5月14日 1:33
- 已标记为答案 CaillenModerator 2016年5月19日 6:43