如何获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7? [英] How to get mshtml.IHTMLDocument6 or mshtml.IHTMLDocument7?

查看:154
本文介绍了如何获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using IE11 in Windows 7. Then I added a reference in C# project c:\Windows\System32\mshtml.tld and try to get mshtml.IHTMLDocument6 or mshtml.IHTMLDocument7, but VS2013 doesn't see it. I can only get mshtml.IHTMLDocument, mshtml.IHTMLDocument2 .. mshtml.IHTMLDocument5.

IHTMLDocument7接口 https://msdn.microsoft.com/ru-ru/library/windows/hardware/ff975572

IHTMLDocument7 interface https://msdn.microsoft.com/ru-ru/library/windows/hardware/ff975572

推荐答案

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

Select the MSHTML assembly reference, look at its Path property and you'll see the problem:


C:\WINDOWS\assembly\ \GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll

C:\WINDOWS\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll

这是mshtml的PIA类型库,安装在安装了VS的任何程序员的计算机上。版本7.0.3300是.NET 1.0时代的版本号,已有14年的历史。当然早于IE11,这就是为什么它没有较晚的界面类型的原因。使用PIA永远不会做错事,它可以确保您的程序可以在任何版本的IE(一直到IE6)上都可以运行。

This is the PIA for the mshtml type library, installed on any programmer's machine that has VS installed. Version 7.0.3300 is a version number from the .NET 1.0 era, it is 14 years old. Predates IE11 of course, that's why it doesn't have the later interface types. Using the PIA is never the wrong thing to do, it ensures that your program will run with any version of IE, all the way back to IE6.

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

But that's not what you want, you'll have to generate your own interop library from the IE11 type library. Run the Visual Studio Command Prompt, navigate to your project directory and type this command:

  Tlbimp c:\windows\system32\mshtml.tlb /out:Interop.mshtml.dll

它将运行一段时间,这是一个很大的问题,并发出一些有关PIA存在的警告,以及一些无法从.NET程序直接使用的模糊方法和类型。您可以忽略它们,它们在PIA中也不起作用。

It will trundle for quite a while, it is a big one, and spit out several warnings about the PIA being present and several obscure methods and types that cannot be directly used from a .NET program. You can ignore them, they didn't work in the PIA either.

您现在在项目目录中拥有Interop.mshtml.dll文件。返回VS,删除旧的MSHTML参考,然后使用项目>添加参考>浏览选择刚刚创建的新参考。默认情况下,其嵌入互操作类型属性为True,完全不再需要PIA,并且您不必在程序中部署文件。

You now have the Interop.mshtml.dll file in your project directory. Back to VS, delete the old MSHTML reference and use Project > Add Reference > Browse to select the new one you just created. Its "Embed Interop Types" property is True by default, no longer a need for a PIA at all and you don't have to deploy the file with your program. Check the file into source control so you only have to do it once.

请注意,当程序在未运行该程序的计算机上运行时,程序可能会因E_NOINTERFACE异常而死亡。已安装所需版本的IE。您可以使用 as 运算符将文档引用转换为IHtmlDocument7,如果IE旧,则为null。

And be careful, your program can die with an E_NOINTERFACE exception when it runs on machine that doesn't have the required version of IE installed. You can use the as operator to cast the document reference to IHtmlDocument7, it will be null if IE is old.

这篇关于如何获取mshtml.IHTMLDocument6或mshtml.IHTMLDocument7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆