This discussion is archived
0 Replies Latest reply: Mar 14, 2011 12:58 PM by 847287 RSS

WindowsAccessBridge.dll Problem Finding Java Windows C#

847287 Newbie
Currently Being Moderated
I have a task where I need to gather information from a java window. I have been trying around to get this to work in C# but am failing to do so. Does anyone have any good examples of code to get data from a textbox?

The following is my helper class I think I might be doing something wrong since the isJavaWindow always returns false when I query something that Java Monkey sees.

#region Structs and P/Invokes
[DllImport("windowsaccessbridge.dll", CallingConvention = CallingConvention.Cdecl)]
internal extern static void Windows_run();

[DllImport("WindowsAccessBridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static void releaseJavaObject(long vmID, IntPtr javaObject);

[DllImport("WindowsAccessBridge.dll", CallingConvention=CallingConvention.Cdecl)]
private extern static bool isJavaWindow(IntPtr window);

[DllImport("WindowsAccessBridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static void getVersionInfo(System.Int32 vmID, out VersionInfo v);

[DllImport("WindowsAccessBridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static bool getAccessibleContextInfo(long vmID, IntPtr ac, out AccessibleContextInfo textInfo);

[DllImport("WindowsAccessBridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static bool getAccessibleTextItems(long vmID, IntPtr at, out AccessibleTextItemsInfo textItems, int index);

[DllImport("WindowsAccessBridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static bool getAccessibleTextInfo(long vmID, IntPtr at, out AccessibleTextInfo textItems, int x, int y);

[DllImport("WindowsAccessBridge.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern bool getAccessibleContextFromHWND(IntPtr hwnd, out long vmID, out IntPtr ac);

[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string lpFileName);

[DllImport("User32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChild, string className, string windowName);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct VersionInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string VMversion;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string bridgeJavaClassVersion;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string bridgeJavaDLLVersion;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string bridgeWinDLLVersion;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct AccessibleContextInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string name;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string description;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string role;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string role_en_US;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string states;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string states_en_US;

[MarshalAs(UnmanagedType.I4)]
public int indexInParent;
[MarshalAs(UnmanagedType.I4)]
public int childrenCount;
[MarshalAs(UnmanagedType.I4)]
public int x;
[MarshalAs(UnmanagedType.I4)]
public int y;
[MarshalAs(UnmanagedType.I4)]
public int width;
[MarshalAs(UnmanagedType.I4)]
public int height;

[MarshalAs(UnmanagedType.Bool)]
public bool accessibleComponent;
[MarshalAs(UnmanagedType.Bool)]
public bool accessibleAction;
[MarshalAs(UnmanagedType.Bool)]
public bool accessibleSelection;
[MarshalAs(UnmanagedType.Bool)]
public bool accessibleText;
[MarshalAs(UnmanagedType.Bool)]
public bool accessibleInterfaces;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct AccessibleTextItemsInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string letter;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string word;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string sentence;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct AccessibleTextInfo
{
[MarshalAs(UnmanagedType.I4)]
public int charCount;
[MarshalAs(UnmanagedType.I4)]
public int caretIndex;
[MarshalAs(UnmanagedType.I4)]
public int indexAtPoint;
}
#endregion

Thanks
Brian

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points