请教一个c#编译问题

yiyamzen yiyamzen 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我编译下面的代码报如下错,是什么问题?是不是需要加 try/catch这个?如果是的话需要在哪里加呢?

Error 1 Cannot register assembly "C:\Users\abc\AppData\Local\Temporary Projects\BHO01\bin\Release\BHO01.dll". Exception has been thrown by the target of an invocation. BHO01


namespace BHO01
{
[
ComVisible(true),
Guid("1070731f-34ea-4763-a4ef-89b25562c553"),
ClassInterface(ClassInterfaceType.None)
]

public 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 OnDocumentComplete(object pDisp, ref object URL)
{
}

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 int SetSite(object site)
{
if (site != null)
{
webBrowser = (WebBrowser)site;
webBrowser.BeforeNavigate2 += new
DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
}
else
{
webBrowser.BeforeNavigate2 -= new
DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
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;

}

}
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
yiyamzen
C# 111,129 成员 642,540 内容