简体   繁体   English

使用Visual C#2010 Express在C#项目中添加引用'SHDocVw'

[英]Add reference 'SHDocVw' in C# project using Visual C# 2010 Express

I am following a tutorial which creates a BHO using MS Visual Studio 2010 and C#. 我正在遵循使用MS Visual Studio 2010和C#创建BHO的教程。 In order to run the tutorial code, I have to add this reference in my project:- 为了运行教程代码,我必须在我的项目中添加以下参考:

using SHDocVw 使用SHDocVw

But it is not available in .NET or COM section in Add References. 但是在“添加引用”的.NET或COM部分中不可用。

So I wanted to ask is this namespace not available in Microsoft Visual C# 2010 Express? 所以我想问这个命名空间在Microsoft Visual C#2010 Express中不可用吗? and if it is available, how to add it. 以及是否可用,如何添加。

This is my halfway project code 这是我的中途项目代码

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;
    }

}

} }

Here are the errors attached:- 这是附加的错误:

Error 1 The type or namespace name 'SHDocVw' could not be found (are you missing a using directive or an assembly reference?) 错误1找不到类型或名称空间名称'SHDocVw'(您是否缺少using指令或程序集引用?)

Error 2 The type or namespace name 'WebBrowser' could not be found (are you missing a using directive or an assembly reference?) 错误2找不到类型或名称空间名称'WebBrowser'(您是否缺少using指令或程序集引用?)

You need to add a reference to a COM component called Microsoft Internet Controls . 您需要添加对称为Microsoft Internet Controls的COM组件的引用。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM