#Persistent pwb := ComObjCreate("InternetExplorer.Application") ComObjConnect(pwb, IE_Events) pwb.Navigate("www.autohotkey.com") pwb.visible := true class IE_Events { DocumentComplete(pwb) { pwb.document.parentWindow.Open("http://www.autohotkey.com") } NewWindow3(ppDisp, Cancel, flags, Url, NewURL, pwb) { TrayTip, , NewWindow3 Event Fired [color=red]Cancel := true[/color] } OnQuit(pwb) { ExitApp } }... or am I just missing something?
Com Events - Using ByRef Parms
Local Variables for IE_Events.NewWindow3() -------------------------------------------------- Cancel[Object]: 0x02401920 <= ComObject([color=red]0x400B[/color], [color=red]0xAB92A8[/color]) flags[1 of 3]: 4 NewURL[26 of 63]: http://www.autohotkey.com/ ppDisp[Object]: 0x024018E0 <= ComObject(0x4009, 0xAB92B8) pwb[Object]: 0x024017F0 <= ComObject(0x0009, 0xA743C4) this[Object]: 0x00142008 Url[26 of 63]: http://www.autohotkey.com/ListVars shows that ComObjType(Cancel) is 0x400B and ComObjValue(Cancel) is 0xAB92A8. 0x400B is a combination of VT_BYREF (0x4000) and VT_BOOL (0xB), which means that 0xAB92A8 is the address of a VARIANT_BOOL value. This type is defined as:
[color=green]/* 0 == FALSE, -1 == TRUE */[/color] typedef short VARIANT_BOOL;You can store a "true" value like so:
NumPut(-1, ComObjValue(Cancel), "short")For ByRef in/out parameters which are VT_DISPATCH (such as ppDisp), VT_UNKNOWN or VT_BSTR, before storing a new pointer at the address returned by ComObjValue(), you must free the previous contents (if non-NULL).
... thanks for reading my mind as well 8)For ByRef in/out parameters which are VT_DISPATCH (such as ppDisp) ...
Lexikos wrote:
For ByRef in/out parameters which are VT_DISPATCH (such as ppDisp) ...
... thanks for reading my mind as well 8)
I think this might be my exact problem.
I created a NewWindow3 event which returns a COM object of type 0x4009 (by ref).
Any property or function (such as ReadyState or Navigate) on that COM throws an error "Error: No valid COM object!"
I have protected mode off, and I've tried running the script as administrator.
I've spent quite some time looking on the google and in the forum without an explicit solution. Any help would be appreciated, I think I'm close.
... nextPage:=false ie2:="" while, !nextPage||ie2=="" { Sleep, 100 } ListVars ie2.Navigate("Google.com") return IE_NewWindow3(ppDisp,Cancel,dwFlags,bstrUrlContext,bstrUrl) { global ie2:=ppDisp global nextPage:=true }
I guess I can back my question up a little bit. I'm using a COM object for IE to access a webpage. I click on a link and that opens a new window. I want the COM object to be able to control that new window.
Thanks for the help and fast response.
In other words, the new window doesn't exist yet.... this event precedes the creation of a new window in the WebBrowser in response to a navigation targeted to a new window, or from script using the window.open method.
Source: NewWindow3 Event (InternetExplorer, WebBrowser)
ppDisp
Object expression that, optionally, receives a new, hidden WebBrowser or InternetExplorer object with no URL loaded.
The application that processes this notification can respond in one of three ways:
Create a new, hidden, non-navigated WebBrowser object or InternetExplorer object that is returned in ppDisp. On return, the object that fired this event configures and navigates (including a BeforeNavigate2 event) the new object to the target location.
Cancel the navigation by setting Cancel to True.
Do nothing and do not set ppDisp to any value. This will cause the object that fired the event to create a new InternetExplorer object as a separate (non-hosted) process to handle the navigation.
if there is another way to do this, please let me know, but i'm pretty sure this is the intent of this method. list vars shows it as a com object by ref type. i came to this thread originally because there was some specific language related to the by ref that i thought i might not be doing correctly/don't know how to do.
thanks for the help.
from previous:
NewWindow3(ppDisp, Cancel, flags, Url, NewURL, pwb)
from microsoft docs:
Private Sub object_NewWindow3( _
ByRef ppDisp As Object, _
ByRef Cancel As Boolean, _
ByVal dwFlags As Long, _
ByVal bstrUrlContext As String, _
ByVal bstrUrl As String)
any help is appreciated. thanks.
I'm trying to do the same thing, get a pointer to the new window, but can't figure out if this is possible using ppDisp. If it is could someone please post an example?
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls
Join the New AutoHotkey Forum!
I second this request for a way to get a pointer to the new window.