zoukankan      html  css  js  c++  java
  • Additional information: 对 COM 组件的调用返回了错误 HRESULT E_FAIL

    1:Winform应用通过mshtml操作IE浏览器DOM时,第一次运行正常,点击第二次时错误信息如下

    A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in openie01.exe

    Additional information: 对 COM 组件的调用返回了错误 HRESULT E_FAIL。

    If there is a handler for this exception, the program may be safely continued.

    2:出现异常的代码 

    为:mshtml.HTMLDocument doc = ie.Document;
    SHDocVw.InternetExplorer ie = getInternetExploer(url);
                if (null == ie) 
                {
                    //如果没有打开,则进行打开操作,并获取ie对象
                    ie = new SHDocVw.InternetExplorer();
                    ie.Navigate(url);
                    ie.Visible = true;
    
                    ie.DocumentComplete += ie_DocumentComplete;
    
                    compWait();
                }
    
                //操作DOM进行模拟登陆
                mshtml.HTMLDocument doc = ie.Document;

    第一次运行正常,是因为进行了加载完成的判断

    private void ie_DocumentComplete(object pDisp, ref object URL)
            {
                ie_Read = true;
            }
    
            private void compWait()
            {
                while (ie_Read != true)
                {
                    Application.DoEvents();
                }
            }

    第二次运行异常,是因为ie_Read这个变量没有置位导致的。

    3:解决方法

    在程序运行完之后将ie_Read置位

     //将标识复位
                ie_Read = false;
  • 相关阅读:
    lnmp环境搭建
    Git常用命令
    博客园写随笔环境搭建
    Win常用软件
    Docker环境搭建
    ESP-8266 RTOS 环境搭建
    查看Linux信息
    博客园markdown语法
    Java后台技术(TDDL)
    Java后台技术(Dubbo入门)
  • 原文地址:https://www.cnblogs.com/yshyee/p/7918676.html
Copyright © 2011-2022 走看看