Thanks for responding guys.
varHwnd is an existing IE's handle.
What I'm trying to do is create an object and run through the list of all active browsers and hook onto the browser that has the window handle (varHwnd).
Here's a better picture of what I'm trying to convert :
Code:
Function HookActiveDoc() As Object
Dim Result As Integer
Dim objBrowserObject As Object, objWinShell As Object, objWindows As Object
Dim varCount As Variant, varHwnd As Variant
Dim objDoc As Object
Set objBrowserObject = Nothing
Set objWindows = Nothing
Set objWinShell = Nothing
Set objDoc = Nothing
'Start: Initialize.
'for testing purposes, assign varHwnd to an existing browser handle
varHwnd = 197378
Set objWinShell = CreateObject("Shell.Application")
Set objWindows = objWinShell.Windows
For varCount = 0 To objWindows.Count - 1
On Error Resume Next
If objWindows(varCount).Hwnd = varHwnd Then
Set objBrowserObject = objWindows(varCount)
If Err = 0 Then
Exit For
Else
Err = 0
End If
End If
Next
'End: Initialize.
If objBrowserObject Is Nothing Then
'objBrowserObject is nothing
Set HookActiveDoc = Nothing
Goto PurgeObj
End If
Set objDoc = objBrowserObject.Document
If objDoc Is Nothing Then
'objDoc is nothing
Set HookActiveDoc = Nothing
Goto PurgeObj
End If
Set HookActiveDoc = objDoc
PurgeObj:
Set objBrowserObject = Nothing
Set objWindows = Nothing
Set objWinShell = Nothing
Set objDoc = Nothing
End Function
This is how I converted the function (but took it out of the function) :
Code:
$varHwnd = 197378
$objWinShell = CreateObject("Shell.Application")
$objWindows = $objWinShell.Windows
If $objWindows = 0
? "objWindows is Nothing"
Sleep 5
Exit 1
EndIf
? "objWindows count : " + $objWindows.Count
For $varCount = 0 to $objWindows.Count - 1
If $objWindows($varCount).Hwnd = $varHwnd
$objBrowserObject = $objWindows($varCount)
If @ERROR = 0
$varCount = $objWindows.Count - 1
EndIf
EndIf
Next
If $objBrowserObject = 0
? "objBrowserObject is Nothing"
Sleep 5
Exit 1
EndIf
$objDoc = $objBrowserObject.Document
However it fails on
Code:
If $objWindows($varCount).Hwnd = $varHwnd
and gives the error message : "ERROR : unexpected command!"