By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,448 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,448 IT Pros & Developers. It's quick & easy.

Active Accessibility in C#

P: n/a
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(IntPt r)));
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;
}

Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.