问题描述
我使用VS 2010 Ultimate.
I use VS 2010 Ultimate.
我试图通过右键单击参考->添加参考... ,然后单击浏览并导航到我的项目参考中,将"shdocvw.dll"添加到项目参考中"C:\ Windows \ System32 \ shdocvw.dll",但是当我单击 Add 按钮时,什么也没有发生.该对话框甚至没有关闭.
I'm trying to add "shdocvw.dll" to my project's references by right clicking References -> Add Reference..., then clicking Browse and navigating to "C:\Windows\System32\shdocvw.dll", but when I click the Add button nothing happens at all. The dialog doesn't even close.
任何想法我会做错什么吗?
Any idea what could I be doing wrong?
我尝试重新启动VS,但始终遇到此问题.
I tried restarting VS but kept having this problem.
推荐答案
在C#解决方案中,如果添加对名为"Microsoft Internet Controls"的COM组件的引用,则应该能够从C#访问SHDocVw命名空间.控制台应用程序,而不必执行任何异常操作.
In your C# solution, if you add a reference to the COM component named "Microsoft Internet Controls", you should be able to access the SHDocVw namespace from a C# console app, without having to do anything unusual.
一旦这样做(在VS 2008中),我便可以使用SHDocVw.ShellWindows,SHDocVw.IWebBrowser2等.例如:
Once I did that (in VS 2008) I was then able to use SHDocVw.ShellWindows, SHDocVw.IWebBrowser2, and so forth. For example:
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.IWebBrowser2 ie in shellWindows)
{
Console.WriteLine("ie.LocationURL: " + ie.LocationURL);
if (ie.LocationURL.Contains("foo.com"))
ie.Quit();
}
使用VS 2012/.NET 4.x时,可以改用下面的方法来解决错误无法嵌入互操作类型'SHDocVw.ShellWindowsClass'."
When using VS 2012/.NET 4.x, you can use the approach below instead, to work around the error "Interop type 'SHDocVw.ShellWindowsClass' cannot be embedded."
using SHDocVw;
// ... snip ...
SHDocVw.ShellWindows shellWindows = new ShellWindows();
foreach (SHDocVw.IWebBrowser2 ie in shellWindows)
{
Console.WriteLine("ie.LocationURL: " + ie.LocationURL);
if (ie.LocationURL.Contains("foo.com"))
ie.Quit();
有关VS 2012问题的更多信息,请参见以下答案:
For more information on the VS 2012 issue, see this answer:
这篇关于无法添加"C:\ Windows \ System32 \ shdocvw.dll";到我的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!