AutoHotkey Community

It is currently May 27th, 2012, 9:06 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: November 1st, 2011, 5:26 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Using IE9 this function does not return the global vars if
the webpage has a <!doctype html> like google.com and facebook.com
have for example.

The JS_to_Inject script to run works OK, just the var(s) are not
being returned with COM_Invoke(pwin,Vars_%A_Index%) . ","

It works fine with IE6,7,8 in W98,XP,Vista,7

Here is a link to MSN Defining Document Compatibility which shows
that the HTML5 mode is caused by the doctype html being used by
these 2 websites. I am sure there will be many others using it.
http://msdn.microsoft.com/en-us/library/cc288325

To test this have the top IEFrame window be google.com. Try it
with google.com, then try it with any almost any other non-google
website.

Code:
#Include COM.ahk
#Include ACC.ahk
return

f6::
;this sets global var mytest and also alerts it. Works in google.com
;so the global var is there.
IE_InjectJS(WinExist("ahk_class IEFrame"), "var myTest='test'; alert(myTest);")

;this gets the myTest value in all IE's except IE9 with HTML5 doctype.
myVar := IE_InjectJS(WinExist("ahk_class IEFrame"), "", "myTest")
MsgBox, 4096,, myVar is: %myVar%
return

;this lets me specify by hwnd, or top IE window etc.                   
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
       break
        }
      }

    ;Initialize the COM interface. code modified from SEAN
   IID_IHTMLWindow2   := "{332C4427-26CB-11D0-B483-00C04FD90119}"
   ACC_Init()
   
   ;un-comment this to see error ONLY in IE9 with HTML5 doctype
   ;COM_Error(True)
     
   pacc := ACC_AccessibleObjectFromWindow(hIESvr)
   pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2)         
   COM_Release(pacc)
     
   ;Execute the Javascript (if there is any).
   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
   }


Any help will be appreciated. I have this function working in hundreds of
cases so I need to keep it. Hopefully the answer lies in Sean's COM.ahk
or ACC.ahk. I would also appreciate links to the latest COM.ahk and
ACC.ahk for AHK basic in case I have out dated versions.

Thanks


Last edited by Visioneer on November 8th, 2011, 5:42 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2011, 9:28 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Hi, I downloaded a later version of COM.ahk which incorporated
ACC.ahk and adjusted my code as shown. However I still get the
error referred to above.

This is the error message box shown by the COM.ahk debugger:

Function Name: "myTest"
ERROR: Unknown name.
(0x80020006)

Will Continue?

Code:
#Include COM.ahk
;#Include ACC.ahk
return

f6::
;this sets global var mytest and also alerts it. Works in google.com
;so the global var is there.
IE_InjectJS(WinExist("ahk_class IEFrame"), "var myTest='test'; alert(myTest);")

;this gets the myTest value in all IE's except IE9 with HTML5 doctype.
myVar := IE_InjectJS(WinExist("ahk_class IEFrame"), "", "myTest")
MsgBox, 4096,, myVar is: %myVar%
return

;this lets me specify by hwnd, or top IE window etc.                   
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
       break
        }
      }

    ;Initialize the COM interface. code modified from SEAN
   IID_IHTMLWindow2   := "{332C4427-26CB-11D0-B483-00C04FD90119}"
;   ACC_Init()
    COM_AccInit()
   
   ;un-comment this to see error ONLY in IE9 with HTML5 doctype
;   COM_Error(False)
     
;   pacc := ACC_AccessibleObjectFromWindow(hIESvr)
    pacc := COM_AccessibleObjectFromWindow(hIESvr)

   pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2)         
   COM_Release(pacc)
     
   ;Execute the Javascript (if there is any).
   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()
    COM_AccTerm()
   
   ;Return a comma seperated list of variables in the order they were passed
   Return Ret
   }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2011, 1:54 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
I need the following
windows version
ahk version

The problem wont be with COM.ahk. It will be most likely the use of MSAA. I ditched this function long ago because of it. But i might be able to give you some new guts for it

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2011, 7:00 pm 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Thanks tank,

I'm using Win7, with AHK basic. IE9 can't be installed with XP btw.
The later com.ahk version I recently downloaded incorporates acc.ahk
which is the MSAA you are thinking?

Are there Com_invoke options/variations to specifically get vars?

Can you try one of your "title" style functions to just get the var from a
google.com/doctype html5 page?


Last edited by Visioneer on November 2nd, 2011, 1:16 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2011, 7:04 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Visioneer wrote:
MSAA ?
it is the basis of acc.com
Microsoft Active Accessability

It will be later tonight when i can get to my home PC and do some testing

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2011, 4:40 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Altered settings on security tab I did it to fast to be able to tell you specifically which ones but you can tinker with them till you figure it out

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2011, 7:34 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Thanks tank,

I have tried many settings with no joy. Maybe you can reset your IE9
to default settings and try again?
Anyway that probably won't be a enough solution for production apps
using COM. Would I want to tell users to make this change(s)? Even if I
could do it programatically would I want to mess with a users security
settings? It may be a great clue to fixing COM however. Great work!

So if we want to elimate ACC as a culprit, can you show a funtion using
only COM which receives the HWND of window instead of your original
TITLE function, using only COM?
Maybe like the one I PMed you?

If this requires IE security tampering, maybe SEAN could take a look at
revising his COM.ahk? Please just use Google as the test webpage.
That should be ubiquitious enough to take seriously, although there
are many more and more are to come for sure.

IE9 doctype HTML5 breaks COM. At least with IE9 default settings.
Agree ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2011, 10:36 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Here is a link that may help someone get COM to work with IE9/HTML5.

http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/965266f1-e4c0-43c2-9436-473d7c9c1f90

Is Sean still with us? If you see this Sean, I hope all is well for you.
Thanks for all your help, and HELP!!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2011, 6:35 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
the problem is not COM at all or HTML5 but the security settings blocking certain actions. I will reset my settings and map you the specific settings tonight

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2011, 1:59 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Thanks tank,

Great game. I am still working on a function that does not use acc.ahk.
I look forward to your security settings, and if there is a way to set
them via ahk.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2011, 5:17 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Here is some code that uses ONLY Com.ahk and still gives the
COM error, so we can eliminate ACC as the culprit. Try it with
google.com as top window, then try it with autohotkey.com as
top window. The Google gives the error and the Autohotkey does
not give the error.

Code:
f6::
myVar = var myTest = "test"; alert(myTest);
IE_InjectJSCOM(WinExist("ahk_class IEFrame"), myVar)
myVar := IE_InjectJSCOM(WinExist("ahk_class IEFrame"), "", "myTest")
MsgBox, 4096,, myVar is: %myVar%, 3
return

Code:
IE_InjectJSCOM(hWnd_MainWindow, JS_to_Inject, VarNames_to_Return="")
{
COM_Init()
;COM_Error(False)
COM_Error(True)

psh := COM_CreateObject("Shell.Application")
psw := COM_Invoke(psh, "Windows")
 
Loop, % COM_Invoke(psw, "Count")
{
HWND := COM_Invoke(psw,"Item[" A_Index-1 "].HWND")
If HWND=%hWnd_MainWindow%
{
pwb := COM_Invoke(psw, "Item", A_Index-1)
window:= COM_Invoke(Document:=COM_Invoke(pwb, "Document"), "parentWindow")
break
}
}

COM_Release(psw),COM_Release(psh)

if !pwb
{
MsgBox, 4096,, Invalid Hwnd called, 3
COM_Term()
Return
}

If JS_to_Inject 
COM_Invoke(window, "execscript", JS_to_Inject)

If VarNames_to_Return {
StringSplit, Vars_, VarNames_to_Return, `,
Loop, %Vars_0%               
Ret .= COM_Invoke_(window,Vars_%A_Index%) . ","
StringTrimRight, Ret, Ret, 1
}
 
COM_Release(pwb),COM_Release(Document),COM_Release(window)
COM_Term()

Return Ret
}


I can't find any posts that say that COM.ahk is dependent on having just certain IE security settings.

This MSDN post talks about the same error with IE9.
http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/965266f1-e4c0-43c2-9436-473d7c9c1f90
It says:
Quote:
While IDispatch->GetIDsOfNames() fails to get a Dispatch ID of the variable in IE9, it turns out that using the result from get_Script() as IDispatchEx instead of IDispatch and calling:

HRESULT hr = pDispEx->GetDispID(CComBSTR(name), fdexNameImplicit, &id);
does result in a valid pointer.

It seems to me that MSDN would be expected to do things to mess
up ahk, com etc. A typical thing they do is force the use of Ex versions
of functions. I think the COM fix might be simply a matter of using the
Ex version of certain funtions.

Another possibility is to use execscript, as that works, to get the var
value or maybe some other COM invoke command that would work.

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2011, 2:09 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Try replacing:
Code:
window:= COM_Invoke(Document:=COM_Invoke(pwb, "Document"), "parentWindow")
... with this:
Code:
IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IHTMLWindow2
window := Com_QueryService(pwb, IID, IID)

You won't have to release the document object after this change.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2011, 3:09 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Hey Jethrow,

That is working in the test code! The var is returned and the Com
Notification Error has gone away. I will try this in my apps asap and let
you know if there are any problems.

You are fantastic.
You too tank.
Thanks a million.

ps: Are there any references to this COM programming you recommend?

pps: The first code I posted at the top, is basically what I have been
using for 6 years of work. (uses acc) So if I switch over to this new
function do you see any differences in implementation. Do you think
you could fix the top code too, if I need to stay with that approach?
Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2011, 3:30 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Visioneer wrote:
Do you think you could fix the top code too, if I need to stay with that approach?

You could always query for the webbrowser, and then re-query for the window :P :
Code:
pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2)
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
pwb := COM_QueryService(pwin,IID_IWebBrowserApp,IID_IWebBrowserApp)
Com_Release(pwin)
pwin := COM_QueryService(pwb,IID_IHTMLWindow2,IID_IHTMLWindow2)
Com_Release(pwb)

That could be condensed down to a nice single-assignment using AutoHotkey_L :lol: :
Code:
iWB := "{0002DF05-0000-0000-C000-000000000046}", iWin := "{332C4427-26CB-11D0-B483-00C04FD90119}"
ControlGet, hwnd, hwnd, , Internet Explorer_Server1, ahk_class IEFrame
Win := ComObj(9,ComObjQuery(ComObj(9,ComObjQuery(ComObj(9,ComObjQuery(Acc_ObjectFromWindow(hwnd),iWin,iWin),1),iWB,iWB),1),iWin,iWin),1)
Win.execScript("foo='bar'")
MsgBox, % Win.foo

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2011, 5:02 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
You the man Jethrow.

On that last AHK_L code, what would be the code to get the Var(s)
for Return Ret ? And the Com releases?

Thanks

Wait I see the Vars, it's too simple. Just the com releases.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, hyper_, tomoe_uehara, Yahoo [Bot] and 76 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group