Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

c# - Cannot add "C:WindowsSystem32shdocvw.dll" to my project

I use VS 2010 Ultimate.

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:WindowsSystem32shdocvw.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?

I tried restarting VS but kept having this problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

EDIT: 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();

For more information on the VS 2012 issue, see this answer:

C# How to get current URL from the IE?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...