Using AccessibleObjectFromEvent

[This is preliminary documentation and subject to change.]

Many client applications need to look up information about specific accessible objects that have generated events. Since the IAccessible interface is the "gateway" to accessible objects, clients must have an easy way to associate WinEvents with the IAccessible interface of the object generating the events. Active Accessibility provides the AccessibleObjectFromEvent function specifically for this purpose. Other times, a client might want to access to an object based on its location, or window handle. Active Accessibility provides the AccessibleObjectFromPoint and AccessibleObjectFromWindow functions.

AccessibleObjectFromEvent accepts much of the same information that a client application receives with an event notification. In effect, when a client hook procedure receives an event notification, it can "recycle" most of the parameters it receives with the notification to call the AccessibleObjectFromEvent function and retrieve the generating object's IAccessible interface pointer.

The AccessibleObjectFromEvent function accepts five parameters total. The first three parameters, hwnd, dwId, and dwChildId, receive information taken directly from the WinEventProc callback function. The hwnd parameter receives the callback function's hwnd parameter, the dwId parameter gets the idChild parameter. The remaining two parameters that AccessibleObjectFromEvent accepts will contain the address of an object's IAccessible interface and a status value. The status value, received in the pvarChild parameter, indicates whether the provided interface belongs to the object that generated the event or its parent object. If a parent object is specified, then the server assumes the responsibility of supporting IAccessible for the child object.

AccessibleObjectFromEvent increases an object's reference count, and must have a corresponding Release to lower the reference count. Even though an object has a reference count greater than zero, that object can still be destroyed, and clients are not guaranteed that getting properties from or calling methods on an object will succeed. This is what Word does with its objects when it quits: As with usual OLE Automation objects, Word will quit and Active Accessibility will CoDisconnect the object so that if anyone tries to access it cross-process after the application quits, OLE will return an error. A reference count on a Active Accessibility object does not reference count the application.