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
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:
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
development team has written this
article where he discusses, among other things, one method for debugging
calling convention declaration errors.