使用 Visual C# 2010 Express 在 C# 项目中添加引用“SHDocVw" [英] Add reference 'SHDocVw' in C# project using Visual C# 2010 Express
问题描述
我正在学习使用 MS Visual Studio 2010 和 C# 创建 BHO 的教程.为了运行教程代码,我必须在我的项目中添加这个引用:-
I am following a tutorial which creates a BHO using MS Visual Studio 2010 and C#. In order to run the tutorial code, I have to add this reference in my project:-
使用 SHDocVw
using SHDocVw
但它在添加引用的 .NET 或 COM 部分中不可用.
But it is not available in .NET or COM section in Add References.
所以我想问一下这个命名空间在 Microsoft Visual C# 2010 Express 中不可用吗?如果可用,如何添加它.
So I wanted to ask is this namespace not available in Microsoft Visual C# 2010 Express? and if it is available, how to add it.
这是我的中途项目代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IEPlugin
{
[
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);
}
[
ComVisible(true),
Guid("2159CB25-EF9A-54C1-B43C-E30D1A4A8277"),
ClassInterface(ClassInterfaceType.None)
]
public class BHO : IObjectWithSite
{
private WebBrowser webBrowser;
public int SetSite(object site)
{
if (site != null)
{
webBrowser = (WebBrowser)site;
webBrowser.DocumentComplete +=
new DWebBrowserEvents2_DocumentCompleteEventHandler(
this.OnDocumentComplete);
}
else
{
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;
}
public void OnDocumentComplete(object pDisp, ref object URL)
{
HTMLDocument document = (HTMLDocument)webBrowser.Document;
}
}
}
这是附加的错误:-
错误 1 找不到类型或命名空间名称SHDocVw"(您是否缺少 using 指令或程序集引用?)
Error 1 The type or namespace name 'SHDocVw' could not be found (are you missing a using directive or an assembly reference?)
错误 2 找不到类型或命名空间名称WebBrowser"(您是否缺少 using 指令或程序集引用?)
Error 2 The type or namespace name 'WebBrowser' could not be found (are you missing a using directive or an assembly reference?)
推荐答案
您需要添加对名为 Microsoft Internet Controls
的 COM 组件的引用.
You need to add a reference to a COM component called Microsoft Internet Controls
.
这篇关于使用 Visual C# 2010 Express 在 C# 项目中添加引用“SHDocVw"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!