The following code just updates (to COM.ahk) Sean's (
http://www.autohotkey.com/forum/topic20979.html) second example of attaching an event sink to a COM object:
Code:
#SingleInstance force
COM_Error(1)
; navTrustedForActiveX = 0x0400
; (added per Tank's iWeb.ahk in some tests)
GoSub, GuiStart
Gui, +LastFound
Gui, Show, w800 h600 Center, WebBrowser
hGui := WinExist()
pwb1 := COM_AtlAxGetControl(COM_AtlAxCreateContainer(hGui, 10, 10, 380, 580, "Shell.Explorer"))
pwb2 := COM_AtlAxGetControl(COM_AtlAxCreateContainer(hGui, 410, 10, 380, 580, "Shell.Explorer"))
psink := COM_ConnectObject(pwb1, "Web_", "DWebBrowserEvents2")
MsgBox, psink is %psink%
COM_Invoke(pwb1, "Navigate", "http://www.autohotkey.com/")
; COM_Invoke(pwb1, "Navigate", "C:\Test.html", navTrustedForActiveX, "_self")
Sleep 5000
COM_Invoke(pwb1, "Navigate", "http://www.autohotkey.com/forum/")
; COM_Invoke(pwb1, "Navigate", "C:\Test2.html", navTrustedForActiveX, "_self")
Sleep 5000
COM_Invoke(pwb1, "GoBack")
Sleep 3000
COM_Invoke(pwb1, "GoForward")
Sleep 3000
Return
GuiStart:
COM_CoInitialize()
COM_AtlAxWinInit()
Return
GuiClose:
Gui, Destroy
COM_Release(psink)
COM_Release(pwb1)
COM_Release(pwb2)
COM_AtlAxWinTerm()
COM_Couninitialize()
ExitApp
Web_NavigateComplete2(prms, this)
{
MsgBox, Got to Web_NavigateComplete2
}
Web_BeforeNavigate2(prms, this)
{
Global pwb2
MsgBox, Got to Web_BeforeNavigate2
COM_Invoke(pwb2, "Navigate", COM_DispGetParam(prms,1))
}
(I've added message boxes to indicate the event sink's creation pointer value, and to indicate whether the COM object DWebBrowserEvents2 events are successfully trapped.)
This code works with IE6, IE7 and IE8 on base (default) installations of Windows XP, XP Service Pack 1, and Vista.
But not on Windows Server 2008! Although psink seems to have been successfully assigned a pointer and pwb1 navigates, neither Web_NavigateComplete2 nor Web_BeforeNavigate2 are ever triggered; hence, the GUI window for pwb2 remains blank.
And this maddening behavior continues whether "Enhanced Security Configuration" is turned on or off, whether accessing local drive files or "Trusted Site" files, whether ActiveX is turned on or off in the security zone, or anything else that I've tried.
Have any of you had experiences similar to this, with Server 2008 or any other OS or with manipulating the webbrowser or IE, where COM_ConnectObject returns a valid value, but the connected object's events are not trapped? Any advice on what to do next would be greatly appreciated.