AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ez_invoke() EZ-COM Wrapper ez_invoke("root.obj.prop[3
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Fri Jan 18, 2008 4:16 pm    Post subject: Reply with quote

i was
Sad
sigh its a good idea i just wish i could get it workin
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Sat Jan 19, 2008 8:07 pm    Post subject: Reply with quote

Tank,

post the Com_Invoke() function from the version of Sean's Script you are using...
_________________
Joyce Jamce
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Mon Jan 21, 2008 2:25 pm    Post subject: Reply with quote

fyi i just went and got this copy again last week
Code:

COM_Invoke(pdisp, sName, arg0="vT_NoNe",arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe")
{
   Global   _hResult_
   nParams   := 10
   sParams   := 0123456789
   Loop,   Parse,   sParams
      If   (arg%A_LoopField% == "vT_NoNe")
      {
         nParams := A_Index - 1
         Break
      }
   sParams   := SubStr(sParams,1,nParams)
   VarSetCapacity(DispParams,16,0), VarSetCapacity(varResult,16,0), VarSetCapacity(IID_NULL,16,0), VarSetCapacity(varg,nParams*16,0)
      NumPut(&varg,DispParams,0), NumPut(nParams,DispParams,8)
   If   (nFlags := SubStr(sName,0) <> "=" ? 3 : 12) = 12
      NumPut(&varResult,DispParams,4), NumPut(1,DispParams,12), NumPut(-3,varResult), sName:=SubStr(sName,1,-1)
   Loop,    Parse,   sParams
      If   arg%A_LoopField% Is Not Integer
               NumPut(8,varg,(nParams-A_Index)*16,"Ushort"), NumPut(COM_SysAllocString(arg%A_LoopField%),varg,(nParams-A_Index)*16+8)
      Else   NumPut(SubStr(arg%A_LoopField%,1,1)="+" ? 9 : 3,varg,(nParams-A_Index)*16,"Ushort"), NumPut(arg%A_LoopField%,varg,(nParams-A_Index)*16+8)
   If (0 =   _hResult_:=DllCall(NumGet(NumGet(1*pdisp)+20), "Uint", pdisp, "Uint", &IID_NULL, "UintP", COM_Unicode4Ansi(wName, sName), "Uint", 1, "Uint", LCID, "intP", dispID))
   && (0 =   _hResult_:=DllCall(NumGet(NumGet(1*pdisp)+24), "Uint", pdisp, "int", dispID, "Uint", &IID_NULL, "Uint", LCID, "Ushort", nFlags, "Uint", &dispParams, "Uint", &varResult, "Uint", 0, "Uint", 0))
   && (3 =   nFlags)
      Result:=(vt:=NumGet(varResult,0,"Ushort"))=8||vt<0x1000&&DllCall("oleaut32\VariantChangeTypeEx","Uint",&varResult,"Uint",&varResult,"Uint",LCID,"Ushort",1,"Ushort",8)=0 ? COM_Ansi4Unicode(bstr:=NumGet(varResult,8)) . SubStr(COM_SysFreeString(bstr),1,0) : NumGet(varResult,8)
   Loop, %   nParams
      NumGet(varg,(A_Index-1)*16,"Ushort")=8 ? COM_SysFreeString(NumGet(varg,(A_Index-1)*16+8)) : ""
   Return   Result
}

_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Mon Jan 21, 2008 7:28 pm    Post subject: Reply with quote

please post the error you get, exactly.

note the latest ez_invoke starts:

Code:
ez_reinvoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe"  )  {



note the "argA" at the end.


if yours doesn't have that... its not the latest ez_invoke....
_________________
Joyce Jamce
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Mon Jan 21, 2008 8:09 pm    Post subject: Reply with quote

@Joy2DWorld
good god man im sorry i cant duplicate the issue now seems to have miraculously healed itself

ok so my next question
is there any way to return javascript variables to ahk with this
kinda like ahklerners IE_InjectJS does
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Mon Jan 21, 2008 8:20 pm    Post subject: Reply with quote

save ya the time of looking for that script
Code:

IE_InjectJS(hWnd_MainWindow, JS_to_Inject, VarNames_to_Return="")
   {
   ;Get a list of the hWnd's owned by the window specified
   WinGet, ActiveControlList, ControlListhWnd, ahk_id %hWnd_MainWindow%
   ;Go throught the list 1 at a time to determine if it is the correct control
   ;This will allow the script to find the current tab in IE7
   Loop, Parse, ActiveControlList, `n
      {
      ;Get the classname of the current control
      WinGetClass, ThisWinClass, ahk_id %A_LoopField%
      ;If the classname is correct and it is visible, it is the correct tab
      If (ThisWinClass = "Internet Explorer_Server") and (DllCall("IsWindowVisible", UInt, A_LoopField))
       hIESvr := A_LoopField
      }
   ;If a control was not found, give a message and return, doing nothing   
   If !hIESvr
      {
      MsgBox, Control "Internet Explorer_Server" not found.
      Return
      }
   ;Initialize the COM interface. code modified from SEAN
   IID_IHTMLWindow2   := "{332C4427-26CB-11D0-B483-00C04FD90119}"
   ACC_Init()
   pacc := ACC_AccessibleObjectFromWindow(hIESvr)
   pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2)
   COM_Release(pacc)
   ;Execute the Javascript (if there is any). Thanks LEXIKOS.
   If JS_to_Inject
      COM_Invoke(pwin, "execscript", JS_to_Inject)
   ;Get the value of the variables, if any.
   If VarNames_to_Return {
      ;Split the passed variable names into a psuedo array of ahk variables
      StringSplit, Vars_, VarNames_to_Return, `,
      ;Get the value of each javascript variable in the order it was passed
      Loop, %Vars_0%
         Ret .= COM_Invoke(pwin,Vars_%A_Index%) . ","
      ;Remove the trailing comma
      StringTrimRight, Ret, Ret, 1
      }
   ; Cleanup
   COM_Release(pwin)
   ACC_Term()
   ;Return a comma seperated list of variables in the order they were passed
   Return Ret
   }

basically uses a couple com_invoke calls most of the script is comments and string manipulation
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Tue Jan 22, 2008 12:23 am    Post subject: Reply with quote

@Tank, review this thread from the start. Then, when you get it working, please post a sample for others. Thanks!
_________________
Joyce Jamce
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Wed Jan 23, 2008 4:16 pm    Post subject: Reply with quote

@Joy2DWorld
ok, i admit it i act smart but i am in reality quite dumb.... dense even.
I have tried things like

Code:

#_pweb := COM_Createobject("InternetExplorer.Application")
ez_Invoke("pweb.Visible=", "True")
ez_Invoke("pweb.Navigate", "http://www.mredkj.com/tutorials/tutorial005.html")
Sleep, 3000


then i try execute some javascript
this works but doesnt allow me to retreive values from
Code:

ez_Invoke("pweb.Navigate", "javascript:var x=document.getElementsByTagName('div');alert(x[15].innerHTML);")

the following would seem to be the natural conversion of the IE_InjectJS script but this doesnt execute at all nor does it seem to give an error

Code:

ez_Invoke("pweb.execscript", "javascript:var x=document.getElementsByTagName('div');alert(x[15].innerHTML);")

the example majkinator posted gives an a blank msgbox
Code:

msgbox % ez_invoke("pwb.doc.getElementsByTagName[div].item[0].innerHTML"); i chaged it to div since the site im going to didnt have tables

however that might be because this isnt really valid javascript it assumes div is a variqable name so it needs to be single or double quoted
so i tried this

Code:

msgbox % ez_invoke("pwb.doc.getElementsByTagName['div'].item[0].innerHTML");

and i got this error
Code:

---------------------------
ez invoke.ahk
---------------------------
Error in #include file "C:\EZ.ahk": The following variable name contains an illegal character:
"#_pwb#_doc#_getElementsByTagName['div']#_item[0]"

The current thread will exit.

   Line#
   027: _param := ez_invoke_findhandle("#_" .  _param , revoke)
   029: _param := "+" . _param
   030: }
   032: Return,Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
   035: }
   037: {
   042: myobject := "#_" . regexreplace(object, "\.", "#_", parts)
--->   046: if ( (handle := %myobject%)  > 0 ) &&  (!revoke || !parts) 
   047: Return,handle
   049: position = 1
   050: Loop
   050: {
   051: if !(position := regexmatch(myobject, "\#_(?<t>\w+)(?:\[(?<ted>\w+)\])?", resul,  position) + strlen(resul) ) 
   053: Break
   055: assem .=  resul 

---------------------------
OK   
---------------------------



the IE_InjectJS works fine for my needs i was just trying to use your ez_Invoke because using it doesnt leave me feeling like a dirty little tramp Very Happy

it also occurs to me that im not being entirely clear on what it is i need exactly

    Need to be able to controle an IE Browser from ahk script

    Need to be able to execute Javascript on this external window

    Need to be able to get the variables from that windows javascripting


I know in my heart im missing something monumentally idiotic but what can i say im just plain dumb. it is almost definately "pebkac"
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Wed Jan 23, 2008 11:44 pm    Post subject: Reply with quote

gosh,


i think you've found a AHK bug...


try latest EZ.ahk version.


better ?


(if not, please let me know).


edit: I think *I* need to get more sleep! Should have looked closer at your error report. Indeed, the code PARSED BY AHK in your error report, reflects a HUGE BUG!!! Somehow AHK is parsing the **OLD** ez_invoke script... instead of the newer/newist/latest/later script code....

have unfixed my sleep deprived 'fix', back to original... (should be slightly faster, i think...)... anyhow...

sorry.
_________________
Joyce Jamce


Last edited by Joy2DWorld on Thu Jan 24, 2008 12:42 am; edited 1 time in total
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Thu Jan 24, 2008 12:01 am    Post subject: Reply with quote

We are assuming im not making some huge bumble in my scripting
Are you saying that after looking at what im doing you think it should have worked?
Im a huge noob please dont take my sarcasm seriously. i really mean it when i say im an idiot
If you see soemthing wrong dont be afraid to call me out i wont take offence
I will try re download ez.ahk
and post back in a sec
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Thu Jan 24, 2008 12:07 am    Post subject: Reply with quote

Code:

#include com.ahk
#include EZ.ahk

COM_CoInitialize()
#_pweb := COM_Createobject("InternetExplorer.Application")
ez_Invoke("pweb.Visible=", "True")
ez_Invoke("pweb.Navigate", "http://www.mredkj.com/tutorials/tutorial005.html")
Sleep, 3000
;msgbox % ez_invoke("pwb.doc.getElementsByTagName[div].item[0].innerHTML")



return
 

gets me when i execute
note i named my test script ez invoke.ahk above is the entirety of that file
Code:

---------------------------
ez invoke.ahk
---------------------------
Error in #include file "C:\Documents and Settings\nbk64jq\My Documents\ahk library\EZ.ahk": Too many parameters passed to function.

Specifically: Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : Com_Invoke(_obje...

   Line#
   038: _object := ez_invoke_findhandle(_object,revoke)
   041: if _obj 
   041: {
   043: if ( _param != _param + 0 ) 
   044: _param := ez_invoke_findhandle( _param , revoke)
   046: _param := "+" . _param
   047: }
--->   057: Return,(_param = "") ? Com_Invoke(_object, arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : (_dualparam = "") ?  Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : Com_Invoke(_object, _param . _dparamQ,regexreplace( _dualparam,"^['""]|['""]$"), arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
   060: }
   062: {
   069: myobject := "#_" . regexreplace(object, "\.", "#_", parts)
   075: if !Revoke &&    !parts &&  !regexmatch(myobject, illegal)  &&   ((handle := %myobject%)  > 0 ) 
   078: Return,handle
   080: position = 1
   081: Loop

The program will exit.
---------------------------
OK   
---------------------------

below is the ez.ahk that i just copied from page one

Code:

;;;;;;;;
ez_reinvoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe"  )  {

return ez_invoke( object,  arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,1 )

}

ez_invoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe", revoke = "" ) {
   ;debug(object "--: " arg1)
   if instr(object,"=+") and  regexmatch(object,"^\s*(?<object>.+?)\s*=\+\s*(?<param>.+)$",_)
      return revoke ? ez_reinvoke(_object "=", "+" ez_invoke(_param, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,revoke) ) : ez_invoke(_object "=", "+" ez_invoke(_param, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8, arg9,argA,revoke ) )
      ;
   if !( (instr(object,".+") ?  regexmatch(object,"^\s*(?<object>.+?)\.(?<obj>\+)(?<param>.+?)\s*$",_) : regexmatch(object,"^\s*(?<object>.+?)((?<param>\w+=?)(?:\[(?<dualparam>\w+|""[^""]*""|'[^']*')\])?(?<dparamQ>=)?"
   ;;(?<param>\w+|\[(?:\w+|""[^""]*"")\]=?"
      ;; (?<param>\w+(?:\[(?<dualparam>\w+|""[^""]*"")\])?=?"
;      . "(?:\."
;         . "(?<param>"
;            . "(?:\w+"
;               . "(?:\["
;                  . "(?:""[^""]*""|\w+)"
;               . "\])?"
;               . "(?:\.\w+)?"
;            . ")+"
;         . "[=]?)"
      . ")?\s*$",_) ))
   ;regexmatch(object,"^\s*(?<object>.+?)\.(?<obj>\+)?(?<param>[\w=]+)\s*$",_) )
      return
     
   ;debug("object is" _object "`nparam is " _param)
/*
   if ! object or !( pos := instr(object,".",0,0))
      return     
   param := substr(object,pos + 1)
   
   object := substr(object,1, pos - 1)
*/     
   if  ( _object != _object + 0 )
      _object := ez_invoke_findhandle(_object,revoke)
   
   
   if _obj {
   
      if  ( _param != _param + 0 )
         _param := ez_invoke_findhandle( _param , revoke)  ; "#_" .

      _param := "+" . _param
   }
   
;   if (A_FormatInteger = "H") {
;      ;swapback = 1
;      SetFormat, Integer, D
;      tmp := Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
;      setFormat, Integer, H
;      return tmp
;   } else
   
      return (_param = "") ? Com_Invoke(_object, arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : (_dualparam = "") ?  Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : Com_Invoke(_object, _param . _dparamQ,regexreplace( _dualparam,"^['""]|['""]$"), arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
   

}

ez_invoke_findhandle(object,revoke ="") {   

   global
   static illegal := "[^\w#@$?\[\]]"

   local myobject, handle, parts, resul, result, resulted, resultisQ, resultedQ, resultedQS,position, assem, value, Ovalue, SmyObject

   myobject := "#_" . regexreplace(object, "\.", "#_", parts)   
   
   
   ;Xbug( "my object is " myobject  "--> " %myobject%)
   
   
   if  !Revoke and   !parts and !regexmatch(myobject, illegal)  and  ((handle := %myobject%)  > 0 )
; BUT I DON'T KNOW WHY THE BELOW LINE IS DIFFERENT ??!! <ie before my workaround added> ???
   ; if  !(revoke or  parts or regexmatch(myobject, illegal) ) and  (Smyobject := regexreplace(myobject,illegal,"?"))  and  ((handle := %Smyobject%)  > 0 )  ; or (strlen(myobject) > 254)
      return  handle

   position = 1
   loop {
      if !(position := regexmatch(myobject, "\#_(?<t>\w+)(?<tisQ>\=)?(?:\[(?:(?<ted>\w+)|""(?<tedQ>[^""]*)""|'(?<tedQS>[^']*)')\])?", resul,  position)
               + strlen(resul) )
         break
     
      assem .=  regexreplace(resul,illegal,"?")
      ;debug("resul " resul "`nassem " assem)
      ;Xbug("assem is " assem )
     
      if (value := %assem%) and (!revoke or (a_index = 1) ) and (Ovalue := value) { ; (strlen(assem) < 254) and
         ;Xbug( "value = assem ==> " value)
         continue
     
      }
     
      if !Ovalue
         return
/*
      ; this.that[3].#[rr].
      if !Ovalue {
         if (a_index = 1) {
            value := substr(assem,3)
            if (Ovalue := %value%) > 0
               continue
         }
         
         return
      }   
*/
     
      ;debug(" result is" result " and resulted is" resulted . resultedQ "`n ovalue is" Ovalue  )
     
      ;Xbug("going to set Ovalue with current ovalue = " ovalue " and result at " result)
      %assem% := Ovalue := (resulted .= resultedQ . resultedQS) ? com_invoke(Ovalue, result . resultisQ, regexreplace(resulted,"\Q#_\E","."))  : com_invoke(Ovalue, result)   
      ;%assem% := Ovalue := (resulted .= resultedQ . resultedQS) ? (result = "_") ? com_invoke(Ovalue,  regexreplace(resulted,"\Q#_\E",".")) : com_invoke(Ovalue, result . resultisQ, regexreplace(resulted,"\Q#_\E","."))  : com_invoke(Ovalue, result)
     
      ;debug( resulted ? "Ovalue, result, resulted, " Ovalue "," result "," resulted        : "")
      ;debug("assem" assem "`nresulted ? " resulted "`nOvalue , result"  Ovalue "," result)
      ;Xbug("set assem  on Ovalue <<-" Ovalue)
     
   
   }
   
   handle := %assem%
   
   return handle
         
}

sorry for being a painfull noob
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Thu Jan 24, 2008 12:13 am    Post subject: Reply with quote

This probably has nothing to do with the problem (which was probably a parsing error), but...
tank wrote:
Code:

ez_Invoke("pweb.execscript", "javascript:var x=document.getElementsByTagName('div');alert(x[15].innerHTML);")
The "javascript:" prefix is only for addresses. In the context of execScript I think it is actually a label. I know other users have used it and you're probably following their lead, but it bothers me.
Quote:
Code:

msgbox % ez_invoke("pwb.doc.getElementsByTagName[div].item[0].innerHTML"); i chaged it to div since the site im going to didnt have tables

however that might be because this isnt really valid javascript it assumes div is a variqable name so it needs to be single or double quoted
ez_invoke has nothing to do with JavaScript. The text in [..] is just that: text. It does not assume div is a variable name; I believe it uses the literal text "div" as the parameter for a function, or index for a property (same thing, really.)
Quote:
Error in #include file "C:\Documents and Settings\nbk64jq\My Documents\ahk library\EZ.ahk": Too many parameters passed to function.
Now it seems you're using an old version of COM.ahk again...
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 678

PostPosted: Thu Jan 24, 2008 2:00 am    Post subject: Reply with quote

@lexikos
thanks for taking interest in such a desparate idiot

i have read enough of your posts to know you know your stuff
here are a couple points of interest in my issue

i just downloaded com.ahk couple days ago
from here
shows last modified file attribute of 1-10-2008



you are right i was just following the lead
ill try without the javascript: label
might be something got messed in the most recent update????
so are you saying this
Code:

ez_Invoke("pweb.execscript", "var x=document.getElementsByTagName(div);alert(x[15].innerHTML);")

should in theory work?
Ill try this tomorrow
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
paulwarr



Joined: 21 Sep 2006
Posts: 30

PostPosted: Thu Jan 24, 2008 4:41 am    Post subject: Reply with quote

Gaining access to the DOM through direct AHK control is nothing short of amazing to me. Thanks to you all for making com.ahk and ez.ahk!

Couple of questions, though (please forgive my ignorance - working through the DOM is still new to me):

Using ez_Invoke, it's possible to chain down through the DOM tree, using the "." nomenclature instead of the "[var]" nomenclature. For example:

msgbox % ez_Invoke("pwb.document.childNodes.0.childNodes.1.innerhtml")
(when the corresponding nodeType = 3)

I've had difficulty, however, invoking other parts of the DOM, such as:

msgbox % ez_Invoke("pwb.document.Forms[0].innerhtml")

This second example (even when multiple forms are present in the page) yields nothing.

So two questions:

1) Any "rules of thumb" as to when to use the "dot" as opposed to the "[]" when writing ez_Invoke expressions?

2) Anybody have any luck when attempting to identify/extract elements from different "element collections"? Any snippets/examples that you could share would be greatly appreciated.

Thanks again for all of the great stuff!
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Thu Jan 24, 2008 8:51 am    Post subject: Reply with quote

tank wrote:
so are you saying this
Code:

ez_Invoke("pweb.execscript", "var x=document.getElementsByTagName(div);alert(x[15].innerHTML);")

should in theory work?
There are at least two problems with that:
  1. What I said before about "div" applies only to ez_Invoke. In this case, ez_Invoke is not interpreting the [] - execScript is. You need ""quote marks"". ("" vs " because it is in an expression.)
  2. ExecScript() is a method of the window object, not the WebBrowser object.
Going back to your previous code,
  • You used "pwb.doc" which is also incorrect. There is no "doc" property in the WebBrowser object - it is "Document". Did you have a var "pwb", or was it "pweb"?
  • I don't understand why you'd use ez_invoke for accessing a single property/method:
    Code:
    COM_CoInitialize()
    #_pweb := COM_Createobject("InternetExplorer.Application")
    ez_Invoke("pweb.Visible=", "True")
    ez_Invoke("pweb.Navigate", "http://www.mredkj.com/tutorials/tutorial005.html")
    ...when its basically the same using COM_Invoke directly, but more efficient since there's no middle-man:
    Code:
    COM_Init()
    pweb := COM_CreateObject("InternetExplorer.Application")
    COM_Invoke(pweb, "Visible=", "True")
    COM_Invoke(pweb, "Navigate", "http://www.mredkj.com/tutorials/tutorial005.html")
Btw, I use the "p" prefix to mean "pointer", but it is practically meaningless with ez_Invoke, since all object #_identifiers are pointers.

paulwarr wrote:
1) Any "rules of thumb" as to when to use the "dot" as opposed to the "[]" when writing ez_Invoke expressions?
Refer to the documentation for the API. If what you want is a property, use dot. For ez_invoke, I think [] is used to denote a parameter list (for a property or method.) Some properties (such as a collection's item property) accept parameters, but most do not.
Quote:
2) Anybody have any luck when attempting to identify/extract elements from different "element collections"?
It is just a matter of identifying the necessary objects/properties.
Quote:
I've had difficulty, however, invoking other parts of the DOM, such as:

msgbox % ez_Invoke("pwb.document.Forms[0].innerhtml")

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("htmlfile")
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.)


Last edited by Lexikos on Thu Jan 24, 2008 12:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 4 of 6

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group