exe中未使用SHDocVw.dll引用

本文关键字:dll 引用 SHDocVw 未使用 exe | 更新日期: 2023-09-27 18:27:37

我在Visual Studio 2010中使用可执行文件而不是对其进行调试时遇到问题。

我想从IE中的选项卡中获取youtube视频的url,我在COM选项卡中引用了:C:'Windows'System32'shdocvw.dll和"Microsoft Internet控件"(即使在调试模式下没有此引用,程序也能正常工作)。

被引用的dll在Debug文件夹中,称为"Interop.SHDocVw.dll"。这是我代码的一部分:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    { //the foreach loop isn't executed when I use the executable file
        foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindowsClass())
        {
            url = ieInst.LocationURL;
            if (url.Contains("youtube"))
            {
                webBrowser1.Document.GetElementById("youtube-url").SetAttribute("value", url);
                webBrowser1.Document.GetElementById("submit").InvokeMember("click");
                usable = url;
                timer1.Start();
            }
        }
    }

当我在Visual Studio中以调试模式运行此程序时,一切都很好,但当我使用可执行文件时,它不起作用,DocumentCompleted会发生多次。

有什么帮助吗?

exe中未使用SHDocVw.dll引用

您可以尝试在DocumentCompleted方法中检查WebBrowser.ReadyState属性。大致如下:

if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
    DoWork();
}

文件:http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.readystate.aspxhttp://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowserreadystate.aspx