Announcement

Collapse
No announcement yet.

Closing the first IE instance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Closing the first IE instance

    I'm trying to close the first Internet Explorer instance.
    Everything works fine, but when finally executing the quit method, the program exits with a GPF.
    What am I doing wrong?

    Heinz Salomon

    Code:
    #INCLUDE "SHDOCVW.INC"
    FUNCTION PBMAIN() AS LONG
      DIM objIE AS IWebBrowserApp
      DIM objShellWins AS IShellWindows
      objShellWins = NEWCOM CLSID $CLSID_SHDocVw_ShellWindows
      IF ISOBJECT(objShellWins) THEN
        PRINT STR$(objShellWins.Count) ' = 1 when tested with 1 IE instance open --> OK
        objIE = objShellWins.ITEM(0)
        IF ISOBJECT(objIE) THEN
          objIE.Quit
        END IF
      END IF
      objIE = NOTHING
      objShellWins = NOTHING
    END FUNCTION

  • #2
    Maybe I should add that I translated the PB code from the following VB 6 code (which runs fine!):

    Code:
    'Reference to C:\WINDOWS\system32\shdocvw.dll set in IDE
    
    Option Explicit
    
    Public Sub Main()
      Dim objIE As SHDocVw.InternetExplorer
      Dim objShellWins As SHDocVw.ShellWindows
      Set objShellWins = New SHDocVw.ShellWindows
      If IsObject(objShellWins) Then
        MsgBox Str$(objShellWins.Count)
        Set objIE = objShellWins.Item(0)
        If IsObject(objIE) Then
          objIE.quit
        End If
      End If
      Set objIE = Nothing
      Set objShellWins = Nothing
    End Sub
    Can anybody help me? What did I do wrong?
    Any hint would be greatly appreciated!!

    Regards
    Heinz Salomon
    Last edited by Heinz Salomon; 19 Mar 2009, 04:41 PM.

    Comment


    • #3
      Use Automation(ID binding) rather than Vtbl binding.

      Note: I did not use the PB COM browser, therefore, the class, interface and symbol names are different from those in your original code.

      Code:
      #COMPILE EXE
      
      #DIM ALL
      
      #INCLUDE "SHELL_IDBIND.INC"
      
      FUNCTION PBMAIN() AS LONG
      
        LOCAL objIE         AS ShellIWebBrowserApp
        LOCAL objShellWins  AS ShellShellWindows
      
        LOCAL vIndex        AS VARIANT
        LOCAL lCount        AS LONG
        LOCAL sName         AS STRING
      
        objShellWins = NEWCOM CLSID $CLSID_SHELLSHELLWINDOWS
        
        IF ISOBJECT(objShellWins) THEN
          OBJECT GET objShellWins.Count TO lCount
          MSGBOX "Count:" + FORMAT$(lCount) ' = 1 when tested with 1 IE instance open --> OK
          vIndex = 0
          OBJECT CALL objShellWins.Item(vIndex) TO objIE
          IF ISOBJECT(objIE) THEN   
            OBJECT GET objIE.Name TO sName
            MSGBOX "Name:" + ACODE$(sName)
            OBJECT CALL objIE.Quit
          END IF
        END IF  
        
        objIE = NOTHING
        objShellWins = NOTHING
        
      END FUNCTION
      Last edited by Dominic Mitchell; 19 Mar 2009, 07:54 PM.
      Dominic Mitchell
      Phoenix Visual Designer
      http://www.phnxthunder.com

      Comment


      • #4
        shdocvw: enumerating all open IE windows

        Sorry guys, I was up all night and thought I was making a new thread, but replied to this one instead.

        Comment

        Working...
        X