| View previous topic :: View next topic |
| Author |
Message |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Thu Jan 24, 2008 12:20 pm Post subject: |
|
|
| Quote: |
| Code: | COM_Init()
gosub MakeDoc
forms := COM_Invoke(doc, "forms")
form := COM_Invoke(forms, "item", 0)
MsgBox % COM_Invoke(form, "innerHtml")
COM_Release(form)
COM_Release(forms)
; or more simply:
form := COM_Invoke(doc, "forms", 0)
MsgBox % COM_Invoke(form, "innerHtml")
COM_Release(form)
; with ez_invoke:
#_doc := doc
MsgBox % ez_Invoke("doc.forms.item[0].innerHtml")
; I wonder why this doesn't work?
MsgBox % ez_Invoke("doc.forms[0].innerHtml")
MakeDoc:
html =
(
<body>
<form><input type="text" name="text1"></form>
<form><input type="button" name="button1"></form>
</body>
)
; Create a HTMLDocument to parse the HTML.
doc := COM_CreateObject("{25336920-03F9-11CF-8FD0-00AA00686F13}")
COM_Invoke(doc, "write", html)
COM_Invoke(doc, "close")
return |
Joy2DWorld, I just noticed ez_Invoke never releases any of the COM objects/pointers it retrieves. That could be... hazardous. (Though now I understand what reinvoke is for.) |
Indeed. Maybe a ez_release function is a good idea....
obviously the whole idea is to turn this very AHK step by step:
| Code: |
form := COM_Invoke(doc, "forms", 0)
MsgBox % COM_Invoke(form, "innerHtml")
COM_Release(form)
|
into VB drop in style
| Code: |
msgbox % ez_invoke("doc.forms[0].innerHtml")
|
ps: could you post example code realizing the 'danger' of countless objects... [would be helpful for me at least, as have not internalized the actualness of the danger...] (in my own, likely flawed testing, creating 100s of thousands of unreleased objects (loop updating doc for example), have not seen ill-effects [which likely there are.. but my own examples have been oblivious to them...] _________________ Joyce Jamce |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Thu Jan 24, 2008 12:45 pm Post subject: |
|
|
Each unique object consumes memory. An object may also be associated with other limited resources in the system, such as network connections, GDI handles, windows, etc. If the object represents a resource in some other process, that process might not be able to close until the object is freed.
Actually, you could do:
| Code: | COM_Release(#_obj), #_obj := 0
| ...but my point was more that ez_Invoke retrieves object pointers and never frees them. (You should do the above when reinvoking, before overwriting the var.)
| Quote: | | (loop updating doc for example) | That would merely increment the reference counter of the document object, not create new objects.
| Quote: | obviously the whole idea is to turn this very AHK step by step ... ]into VB drop in style
| You could use ws4ahk or a ScriptControl via COM.ahk to run actual VBscript or JScript... I'm sure you're aware of both, so why did you write ez_Invoke? |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 679
|
Posted: Thu Jan 24, 2008 3:36 pm Post subject: |
|
|
actually i use ws4ahk all the time with vb code and love it
funny i just never thought of using it for dom. It is fairly well documented and erictheturtle knows his stuff always seems to answer real fast and as of today there is a new version
@lexikos
| Quote: |
ExecScript() is a method of the window object
|
this much i had figured out from the msdn
without checking i just assumed(very incorrectly) based on some posts that ez_invoke just took the string apart and inserted "Window" part at the fron in executeing the code
var x=document.getElementsByTagName(div);
to
var x=window.document.getElementsByTagName(div);
also as cool as ws4ahk is there is a "sexy" feel to this concept for me altho its kinda duplicating erictheturtle's fine additional enhancement of the almighty com god Sean. Im still learning(arent we all) and dont have the massive headstart that alot of members of this community have. I ask dumb questions and i do learn from the insightfull answers.
For those un familiar with ws4ahk that find this thread.
It is super easy to pass AHK variables into vb or jscript with that library and then to get Global variables back out of it. There are just some things that AHK does a bit easier and quite a few things done easier in VB or jscript. And sometimes its a matter of familiarity
tho i have used vb to control many other applications i have never bothered working with internet explorer. I imagine it would be as simple as creating an InternetExplorer.Application active x object and then using the indexed window object i want and then accessing the dom
again thanks for pointing me at what really should have been an obvious path _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Thu Jan 24, 2008 4:32 pm Post subject: |
|
|
| tank wrote: | without checking i just assumed(very incorrectly) based on some posts that ez_invoke just took the string apart and inserted "Window" part at the fron in executeing the code
var x=document.getElementsByTagName(div);
to
var x=window.document.getElementsByTagName(div);
| You seem to have missed my point: you are calling pweb.execScript(). Assuming pweb is a WebBrowser, execScript() does not exist. It would need to be something like pweb.Document.parentWindow.execScript(). Even so, what that particular JavaScript does is possible with ez_invoke alone.
| Code: | COM_Init()
doc := COM_CreateObject("htmlfile")
Loop, 16
COM_Invoke(doc, "write", "<div>" A_Index "</div>")
COM_Invoke(doc, "close")
#_doc := doc
MsgBox % ez_Invoke("doc.getElementsByTagName[div].Item[15].innerHTML") ; shows "16" |
This is JavaScript: | Code: | | var x=document.getElementsByTagName(div); | It is completely unrelated to ez_invoke, which passes it, untouched, to the target function (assuming the target function exists!) It is valid to omit "window." since all or most members of the window object are in the global namespace. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 679
|
Posted: Thu Jan 24, 2008 4:44 pm Post subject: |
|
|
@lexikos
ok so i did miss that point but i do not wish to write then access dom from an ahk script i want to grab an existing internet explorer window already open to a given site and execute javascript and get dom objects from it perhaps even execute dom methods
again thanks for running the class as i try desparately to pass from noobdom to the elevated level of villiage idiot _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Fri Jan 25, 2008 1:18 am Post subject: |
|
|
| tank wrote: | i want to grab an existing internet explorer window already open to a given site and execute javascript and get dom objects from it perhaps even execute dom methods
| My example shows exactly how to do the last part without JavaScript. For instance,
| Code: | ez_Invoke("pweb.Document.parentWindow.execscript", "var x=document.getElementsByTagName(""div"");alert(x[15].innerHTML);")
| becomes
| Code: | MsgBox % ez_Invoke("pweb.Document.getElementsByTagName[div].Item[15].innerHTML")
| I write a document in my example(s) rather than look for an IE window because it makes the example(s) more concise and self-contained. |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Fri Jan 25, 2008 2:37 am Post subject: |
|
|
ez_Invoke("pweb.Document.getElementsByTagName[""div""].Item[15].innerHTML")
and
ez_Invoke("pweb.Document.getElementsByTagName['div'].Item[15].innerHTML")
also valid.
ie. ""div"" the "" is needless, but works so can drag & drop directly. _________________ Joyce Jamce |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 679
|
Posted: Fri Jan 25, 2008 4:45 am Post subject: |
|
|
thank you both for entertaining a helpless noob
Im going to digest and try learn from both of you in hopes of becoming just a little smarter than an average idiot
I sincerely hope i havent left you both in a fit of fury but i will learn
thanks again _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 679
|
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Thu Apr 10, 2008 12:24 am Post subject: |
|
|
interesting. _________________ Joyce Jamce |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 679
|
Posted: Mon Jun 30, 2008 3:44 am Post subject: |
|
|
help me out here where i am going wrong
this doesnt work
| Code: | COM_CoInitialize()
#_oShell := COM_CreateObject("Shell.Application")
msgbox % ez_revoke("oShell.Windows.Item[1].LocationName")
|
this does
| Code: | COM_CoInitialize()
msgbox % COM_Invoke(pwb:=COM_Invoke(psw := COM_Invoke(psh:=COM_CreateObject("Shell.Application"), "Windows"), "Item", 1), "LocationName") |
any help here woiuld be grand looks like i could shorten a bit of code but im just not getting it _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Mon Jun 30, 2008 4:00 am Post subject: |
|
|
| Code: | COM_CoInitialize()
#_oShell := COM_CreateObject("Shell.Application")
msgbox % ez_revoke("oShell.Windows.Item[1].LocationName")
|
| Code: | COM_CoInitialize()
msgbox % COM_Invoke(pwb:=COM_Invoke(psw := COM_Invoke(psh:=COM_CreateObject("Shell.Application"), "Windows"), "Item", 1), "LocationName") |
LocationName of "LocationName".
[untested]
try:
| Code: | COM_CoInitialize()
#_oShell := COM_CreateObject("Shell.Application")
msgbox % ez_invoke("oShell.Windows.Item[1]","LocationName")
|
or even
| Code: | COM_CoInitialize()
#_oShell := COM_CreateObject("Shell.Application")
msgbox % ez_invoke("oShell.Windows.Item[1].LocationName")
|
_________________ Joyce Jamce
Last edited by Joy2DWorld on Mon Jun 30, 2008 4:03 am; edited 1 time in total |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 679
|
Posted: Mon Jun 30, 2008 4:03 am Post subject: |
|
|
| Code: | Function Name: "Item"
ERROR: Invalid number of parameters.
(0x8002000E)
ERROR2: Member not found.
(0x80020003) |
nope no dice _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 679
|
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Mon Jun 30, 2008 4:14 am Post subject: |
|
|
yeah,
COM_CoInitialize()
#_psh:=COM_CreateObject("Shell.Application")
msgbox % psw := COM_Invoke(#_psh, "Windows")
msgbox % pwb:= COM_Invoke(psw, "Item", 1)
not successful... _________________ Joyce Jamce |
|
| Back to top |
|
 |
|