Active Accessibility in C#

A

andyalmq

I'm trying to utilize the Active Accessibility SDK in order to create a
test automation tool. I've been attempting with no success to utilize

AccessibleObjectFromWindow using PInvoke in C#. I'm no wizard with
PInvoke, in fact this is really the first case where I've had to
utilize it much at all.

I believe what I have is close to working, but I keep receiving an
invalid argument exception when the actual function is called. Any
help would be appreciated.

I'm 90% sure I'm passing a valid hwnd, and I'm passing IID_iACCESSIBLE
as is defined below. and OBJID_WINDOW as defined below. The HWND I'm
using is being obtained through a call to FindWindow.


Thanks,

Andyalmq

Here's the code I currently have:

[DllImport("Oleacc.dll", EntryPoint="AccessibleObjectFromWindow")]
private static extern int _AccessibleObjectFromWindow(int /*HWND*/
hwnd, int /*DWORD*/ dwObjectID, /*REFIID*/ System.Guid riid,
/*[MarshalAs(UnmanagedType.Interface)]*/ out System.IntPtr
ppvObject);
public static Guid IID_IACCESSIBLE = new Guid(0x1ea4dbf0, 0x3c3b,
0x11cf, 0x81, 0x0c, 0x00,0xaa, 0x00, 0x38, 0x9b,0x71);
public static int OBJID_WINDOW = 0x00000000;

public static int AccessibleObjectFromWindow(int hwnd, int dwObjectID,
System.Guid riid, IAccessible ppvObject)
{
IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
Marshal.WriteIntPtr(ptr, IntPtr.Zero);

int result = _AccessibleObjectFromWindow(hwnd, dwObjectID, riid, out
ptr);
if (result == 0)
{
ppvObject =
(IAccessible)Marshal.GetObjectForIUnknown(Marshal.ReadIntPtr(ptr));
}
return result;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top