Using the MSAA IAccessible interface within a Delphi Application

I’ve been investigating Microsoft‘s IAccessible
interface recently and thought I would begin a series of posts related to using
IAccessible in a Delphi
application from an MSAA
server perspective.  From the MSDN:

”The IAccessible interface is the heart of Microsoft Active Accessibility.
Applications implement this Component Object Model (COM) interface to represent
their custom user interface elements, which can include their client area as
accessible objects, if necessary.”

In order to start using IAccessible the first step is to import the
oleacc.dll type library which provides us with the necessary interface
declarations.  Having dug into this interface a bit I can save you a little time
and simply give you the TLIBIMP command line necessary to properly import this
type library.

tlibimp -Hs- -Hr- -Ftoleacc -Ps- -O- %systemroot%\SYSTEM32\OLEACC.DLL

If you’d like to import this type library from within the IDE make sure
to set Delphi’s type library importer so that it does not map the interface
declarations as safecall since some of the interfaces require a specific
HRESULT.  To do that select Tools|Options and change the Type Library option for
“Safecall function mapping” to “Do not map”.

The second step is to check the declaration of NotifyWinEvent API located in
Windows.pas to make sure it’s correct.  I found that it wasn’t declared as
stdcall which resulted in an AV whenever I called it.  If you ever find yourself
getting an AV when you call a Windows API function double check the declared
calling convention of the function import before going any further.

Here is the corrected declaration:

procedure NotifyWinEvent(event:
DWORD; hwnd: HWND; idObject, idChild: Longint); stdcall;

Ok, now that we have those two steps out of the way we’ve opened the door to
enabling our Delphi applications through MSAA.  Since this is a fairly large
topic I’m going try and tackle it in small pieces so stay tuned for the next
step.  In a future post I’ll begin to discuss actually putting this interface to

[UPDATED: Dec 2, 2004 2:14pm PST] Chris Hesik of the Delphi
development team has written this
 where he discusses, among other things, one method for debugging
calling convention declaration errors.

4 thoughts on “Using the MSAA IAccessible interface within a Delphi Application

  1. Did you ever write anymore articles. I’m using Delphi 6 and have an ActiveX control that runs in IE. I wanted to investigate implementing accessibility stuff, but I haven’t seen any examples in the internet.

  2. Hi Mark,
    Unfortunately, I never got back to this partly because the example I was going to talk about was for a MainMenu system (TActionMainMenuBar) but it didn’t really seem all that applicable since the vast majority of people don’t develop main menu controls. At present, the TActionMainMenuBar does implement the IAccessible interface so there is an example of how this interface can be used included with the VCL. The code is included with Delphi 2005, BDS 2006 and the Turbo products.
    That said, this is a topic I would like to get back to though it looks like Microsoft may have changes strategies again regarding adding Accessibility support to Windows applications so I need to do some more investigation.

  3. Hey,
    Could you tell me how to implement the IAccessible interface within a Flex application so as to expose the Flex objects to TestComplete.

Comments are closed.