I'm trying to use the win32 api function AccessibleObjectFromWindow() from python. So far, I've managed to use ctypes to actually call it with proper arguments via the oleacc.dll

The way AccessibleObjectFromWindow works in C is it fills in a void ** buffer which points to a IAccessible pointer. Now, I have been to call AccessibleObjectFromWindow and get a pointer value for the IAccessible stored in a c_int (or c_buffer). And I also know how to use Makepy to parse the Accessibility tlb to get access to the IAccessible interface itself.

What I can't seem to figure out is how do I transform this 4-bytes pointer value into an actual python object that I can treat as an IAccessible (or IDispatch or IUnknown) pointer?

Here is some sample code:

oleAccDll = ctypes.oledll.oleacc
AccessibleObjectFromWindow = oleAccDll.AccessibleObjectFromWindow
IID_IAccessible = ctypes.c_int.in_dll(oleAccDll, "IID_IAccessible")

# you could also say: IID_IAccessible = ctypes.com.GUID( "{618736E0-3C3D-11CF-810C-00AA00389B71}" )

def callback(hwnd, extra):
  acc = ctypes.c_int()
  hr = AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, ctypes.byref(IID_IAccessible), ctypes.pointer(acc))
  print("hr is %s, acc is %x" % (hr, acc))

win32gui.EnumWindows(callback, None)
More info about AccessibleObjectFromWindow is available here:

Thanks so much for your help! Feel free to email me for more info...