Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7?_C#_Internet Explorer 11_Ihtmldocument - Fatal编程技术网

C# 如何获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7?

C# 如何获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7?,c#,internet-explorer-11,ihtmldocument,C#,Internet Explorer 11,Ihtmldocument,我在Windows7中使用IE11。 然后我在C项目C:\Windows\System32\mshtml.tld中添加了一个引用,并尝试获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7,但VS2013没有看到它。 我只能获取mshtml.IHTMLDocument,mshtml.IHTMLDocument2。。mshtml.IHTMLDocument5 IHTMLDocument7接口选择MSHTML程序集引用,查看其路径属性,您将看到问题: C:\WI

我在Windows7中使用IE11。 然后我在C项目C:\Windows\System32\mshtml.tld中添加了一个引用,并尝试获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7,但VS2013没有看到它。 我只能获取mshtml.IHTMLDocument,mshtml.IHTMLDocument2。。mshtml.IHTMLDocument5


IHTMLDocument7接口

选择MSHTML程序集引用,查看其路径属性,您将看到问题:

C:\WINDOWS\assembly\GAC\Microsoft.mshtml\7.0.3300.0\uuu b03f5f7f11d50a3a\Microsoft.mshtml.dll

这是mshtml类型库的PIA,安装在任何安装了VS的程序员机器上。版本7.0.3300是.NET 1.0时代的版本号,已有14年历史。当然,这就是为什么它没有更晚的接口类型。使用PIA从来都不是一件错误的事情,它可以确保你的程序可以运行任何版本的IE,一直到IE6

但这不是您想要的,您必须从IE11类型库生成自己的互操作库。运行Visual Studio命令提示符,导航到项目目录并键入以下命令:

  Tlbimp c:\windows\system32\mshtml.tlb /out:Interop.mshtml.dll
它将运行相当长的一段时间,这是一个大的,并吐出了一些关于PIA存在的警告,以及一些无法从.NET程序直接使用的模糊方法和类型。你可以忽略他们,他们也不在PIA工作

现在,项目目录中有Interop.mshtml.dll文件。返回VS,删除旧的MSHTML引用,并使用Project>Add reference>Browse选择刚刚创建的新引用。默认情况下,它的Embed Interop Types属性为True,不再需要PIA,并且您不必在程序中部署该文件。将文件签入源代码管理,这样您只需执行一次

而且要小心,当您的程序在没有安装所需IE版本的机器上运行时,可能会出现E_NOINTERFACE异常。您可以使用as运算符将文档引用强制转换为IHtmlDocument7,如果IE是旧的,则它将为null