COM_AccessibleObjectFromWindow - 64bit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

COM_AccessibleObjectFromWindow - 64bit

01 Jan 2019, 12:22

[Moderator's note: Topic moved from Bug Reports.]

Hello all, happy New Year!
I use 64-bit AHK_L unless something forces me not to, and I ran into a COM snag, which was easy to work around thanks to Joe Glines.

Code: Select all

COM_AccessibleObjectFromWindow(hWnd, idObject=-4, IID = "")
{
	If	DllCall("oleacc\AccessibleObjectFromWindow", "Uint", hWnd, "Uint", idObject, "Uint", COM_GUID4String(IID, IID ? IID : idObject&0xFFFFFFFF==0xFFFFFFF0 ? "{00020400-0000-0000-C000-000000000046}":"{618736E0-3C3D-11CF-810C-00AA00389B71}"), "UintP", pacc)=0
	Return	pacc
}
This runs fine grabbing an Excel object with AHK_L 1.1.30.1 32-bit. I can access an object and operate on it.
However, if I switch back to AHK_L 1.1.30.1 64-bit, I get the following error(s):

Code: Select all

---------------------------
COM Error Notification
---------------------------
Function Name:	"ActiveSheet"
ERROR:	No COM Dispatch Object!
	()

Will Continue?
---------------------------
Yes   No   
---------------------------
This is solved if I use Joe Glines's code here:

Code: Select all

ObjectFromWindow(hWnd, idObject = -4){
(if Not h)?h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
    If DllCall("oleacc\AccessibleObjectFromWindow","Ptr",hWnd,"UInt",idObject&=0xFFFFFFFF,"Ptr",-VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
    Return ComObjEnwrap(9,pacc,1)
}
I don't know if this qualifies as a bug, and for me it's no longer a problem thanks to Joe, but might it be worth updating the standard COM library to make this particular function (i.e. Com_AccessibleObjectFromWindow) to support both 32-bit and 64-bit systems?

Regards,
burque505
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: COM_AccessibleObjectFromWindow - 64bit

01 Jan 2019, 12:37

Which COM Standard library?
Recommends AHK Studio
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: COM_AccessibleObjectFromWindow - 64bit

01 Jan 2019, 13:04

Thanks for responding, nnnik.
;------------------------------------------------------------------------------
; COM.ahk Standard Library
; by Sean
; http://www.autohotkey.com/forum/topic22923.html
;-----
Maybe not standard despite the name. What I have installed is attached.
I've looked through quite a few variants of it that are in various online locations, and they all seem to have the same COM_AccessibleObjectFromWindow function definition.
Regards,
burque505
com.zip
(5.14 KiB) Downloaded 82 times
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: COM_AccessibleObjectFromWindow - 64bit

01 Jan 2019, 13:06

Isn't this library generally considered to be dead?
Also I dont understand how this is a bug within the AutoHotkey language.
Maybe you could make a new post about the library in the Scripts and Functions forums.
Recommends AHK Studio
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: COM_AccessibleObjectFromWindow - 64bit

01 Jan 2019, 13:20

EDITED: I don't know if it's considered to be dead or not. Some functions appear to still work fine with 64-bit and be required for working scripts. I can't think offhand of any scripts I use on a routine basis that DO require that lib.

As I mentioned,
I don't know if this qualifies as a bug
I guess if it's in a LIB, probably (almost certainly) not.
Is there any COM function built-in now that would provided what COM_AccessibleObjectFromWindow() or the Joe Glines function above do?
Regards,
burque505
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: COM_AccessibleObjectFromWindow - 64bit

01 Jan 2019, 17:42

I think the link you posted is a more outdated than, this, check it out: https://www.autohotkey.com/boards/viewt ... =6&t=26201
"Acc.ahk" is what you want to look at. Look at how there is an Acc_Init function called that wasn't on your first copied code.
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: COM_AccessibleObjectFromWindow - 64bit

01 Jan 2019, 19:37

@safetycar, thanks! I'll take a look. Actually made a Word_Get and PPT_Get function before, jeeswg and I went back and forth on it, take a look here.
Regards,
burque505
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: COM_AccessibleObjectFromWindow - 64bit

30 May 2021, 16:28

I found that AccessibleObjectFromWindow does not return iaccessible interface from uint64 window handles, like this hwnd := 0xffffffff80400b6c.
So I change function to this and now it works:

Code: Select all

Acc_ObjectFromWindow(hWnd, idObject = -4)
{
	Acc_Init()
        varsetcapacity(var, 8, 0)
        numput(hwnd, var, 0, "uint64")
        hwnd := numget(var, 0, "uint")
	If	DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
	Return	ComObjEnwrap(9,pacc,1)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], wineguy and 339 guests