AutoHotkey Community

It is currently May 27th, 2012, 10:39 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: October 5th, 2010, 11:05 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
It should be rather obvious: COM_Enwrap and corresponding object are implemented in COM.ahk, whereas ComObjEnwrap is built-in and entirely separate.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 8th, 2010, 1:28 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Is it possible to retrieve a javascript array through dispatchobj_param() ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 8th, 2010, 5:22 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
You may retrieve a pointer. I would've thought a JS array would be a regular COM object. If so, DispatchObj_Param should return a COM object pointer; otherwise a SAFEARRAY pointer. I think Sean has since added a function to COM.ahk (something like COM_GetDispParam) which might be more complete.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 14th, 2010, 11:02 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
would dispatchobj require its interface to be registered and the std marshaller {00020424-0000-0000-C000-000000000046} to be set in the registry at HKCR\Interface\{dispatchobj iid}\ProxyStubClsid32 ?. I need to get a safe array of bytes with lbound = 1 out of an activex control in IE. I think I am having problems because it is in a separate process...

Is it possible to get array items out of a vbscript array directly from ahk using safearrayaccessdata instead of eval like in this script found here
Code:
oSC := ComObjCreate("ScriptControl")

; define the Language
oSC.Language := "VBScript"

; define the VBScript
script =
(
Dim string
Arr = Array("Auto", "Hot", "key!")
For Each i In Arr
   string = string & i
Next
MsgBox "Joined Array Elements:" & vbCR & string, 64, "VBScript MsgBox"
)

; execute the VBScript
oSC.ExecuteStatement(script)

; extract values from the VBScript
MsgBox, 64, AutoHotkey MsgBox, % "Joined Array Elements:`n" oSC.Eval("Arr(0) & Arr(1) & Arr(2)")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 15th, 2010, 3:28 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
No. Yes.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 15th, 2010, 6:07 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Lexikos wrote:
No. Yes.
Thanks for the ray of hope. Figured it out. Its a little convoluted, have to send vbscript array through a jscript function... But it works ! What am I missing ?
safearray.html
Code:
   <html><title>safearray</title>
<script language="VBscript">
Dim myArray(3)
myArray(0) = "ahk"
myArray(1) = "rocks"
myArray(2) = "ie and"
myArray(3) = "com"
Function sendarray()
ahk.getarray myArray, "hello"
End Function
</script>

   <script language="JScript">
      function sendarrayjs(a)
{
ahk.getarray(a);
}
   </script>
   <body>
    <button id="okButton" onclick="sendarray" language="VBScript">getarrayvb doesn't work</button>

    <button onclick="sendarrayjs(myArray)" language="JScript">getarrayjs works</button>

   </body>
   </html>
getsafearray.ahk
Code:
obj := DispatchObj_Create("getarray")
cobj := comobjenwrap(obj)
iewin := getiewin("safearray")

;;; script
script =
(
var ahk;
)
;;; exec
iewin.execScript(script, "JScript")
iewin.ahk := cobj
return
;; getarray(this, params, result)
getarray(this, params, result)
{
    msgbox in getarray
    param1 := DispatchObj_Param(params, 1, type1)
    param2 := DispatchObj_Param(params, 2, type2)
    SetFormat, integer, hex
    type1 += 0
    type2 += 0
    msgbox % "param1: " param1 "param2: " param2 "type1: "  type1  "type2: "  type2
    SetFormat, integer, d
_arr := param1
lbound := SafeArrayGetLBound(_arr, 1 )
ubound := SafeArrayGetUBound(_arr, 1 )
adims := SafeArraygetdim(_arr)
pvdata := SafeArrayAccessData(_arr)
msgbox % "lbound: " lbound "ubound: " ubound "admins: " adims
loop, 4
msgbox % SafeArrayGetElement(_arr, A_Index - 1 )

}
;; includes
#include com.ahk
#include dispatchobj.ahk
#include acc.ahk
#include safearray.ahk

;; ui
!r::reload
!q::exitapp

;; getiewin(title)
getiewin(title)
{
ControlGet, hIESvr, Hwnd,, Internet Explorer_Server1, %title%
ACC_Init() ; Call this once only, or call ACC_Term() for each ACC_Init().
           ; Note ACC_Init also calls COM_Init(), so you don't need both.
ieAcc := ACC_AccessibleObjectFromWindow(hIESvr)
IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"
ieWin := COM_QueryService2(ieAcc,IID_IHTMLWindow2,IID_IHTMLWindow2)
COM_Release(ieAcc)
return ieWin
}
;; COM_QueryService2()
COM_QueryService2(ppv, SID, IID = "")
{
   If   DllCall(NumGet(NumGet(1*ppv:=COM_Unwrap(ppv))), "Uint", ppv, "Uint", COM_GUID4String(IID_IServiceProvider,"{6D5140C1-7436-11CE-8034-00AA006009FA}"), "UintP", psp)=0
   &&   DllCall(NumGet(NumGet(1*psp)+12), "Uint", psp, "Uint", COM_GUID4String(SID,SID), "Uint", IID ? COM_GUID4String(IID,IID):&SID, "UintP", ppv:=0)+DllCall(NumGet(NumGet(1*psp)+8), "Uint", psp)*0=0
   Return   ComObjEnwrap(ppv)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 15th, 2010, 10:17 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Look at type1. VBScript clearly passes a variable reference, i.e. VT_BYREF|VT_VARIANT (0x400C), so param1 is a pointer to a VARIANT not a SAFEARRAY. The type of value this VARIANT contains seems to be VT_BYREF|VT_ARRAY|VT_VARIANT (0x600C), i.e. a pointer to a pointer to a SAFEARRAY of VARIANTs. Above _arr := param1, insert this:
Code:
    while (type1=0x400C) { ; VT_BYREF | VT_VARIANT
        type1  := NumGet(param1+0,0,"ushort")
        param1 := NumGet(param1+8)
    }
    if (type1=0x600C) ; VT_BYREF | VT_ARRAY | VT_VARIANT
        param1 := NumGet(param1+0)
...or better yet, you could validate the parameter:
Code:
    while (type1=0x400C) { ; VT_BYREF | VT_VARIANT
        type1  := NumGet(param1+0,0,"ushort")
        param1 := NumGet(param1+8)
    }
    if ((type1 & 0x2fff) = 0x200C) { ; VT_ARRAY | VT_VARIANT, possibly VT_BYREF
        if (type1 & 0x4000) ; VT_BYREF
            param1 := NumGet(param1+0)
        ... code to access safearray goes here ...
    }
    else msgbox wrong type


Edit: Btw, the ACC functions you've used also exist in COM.ahk (with COM_ prefix), so you don't need both files.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 4th, 2011, 1:29 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Thanks for that example. I was able to translate it to extract the Vbs array I needed. Ofcourse native support for safearray made the whole process supereasy.

Is it possible to register Dispatchobj with com using a clsid and program id so it can be used from other applications without the ahk script having to know about the other application ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2011, 1:57 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
tinku99 wrote:
Is it possible to register Dispatchobj with com using a clsid and program id so it can be used from other applications without the ahk script having to know about the other application ?

Yes, I even once wrote a demo on how to do it. It can be found here (it's in the examples).

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 4th, 2011, 2:37 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
fincs wrote:
tinku99 wrote:
Is it possible to register Dispatchobj with com using a clsid and program id so it can be used from other applications without the ahk script having to know about the other application ?

Yes, I even once wrote a demo on how to do it. It can be found here (it's in the examples).
Thanks. I hadn't looked in the zip file, although you did allude to a second example that allowed exactly this.
ComObjActive is sufficient for my purposes, but if you want to extend functionality, you may want to look at the win32com/server code for python.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2011, 3:16 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
This had been done ages ago.
http://www.autohotkey.com/forum/topic25746-55.html

I used to execute CoRegisterClassObject/RegisterActiveObject at the start of my resident AHK script, but, removed them long ago as I didn't need them much myself.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 12 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