10

I have a sample Java app that I got when I downloaded javaaccessablity-2.0.2 that makes use of Java Accessibility (via the Java Access Bridge WindowsAccessBridge-32.dll). Although it calls the getAccessibleContextFromHWND successfully it returns false. Please note that I get the correct value for hWnd which I verified through Inspect tool.

I have a 64-bit Java SDK installed in my windows 64-bit system. And the following is the code I tried. I have tried with WindowsAccessBridge-64.dll also but it gives the same behavior which is vmID and _acParent are returned as zero instead of non zero values.

class Program
{

    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("WindowsAccessBridge-32.dll", CallingConvention = CallingConvention.Cdecl)]
    public extern static bool getAccessibleContextFromHWND(IntPtr hwnd, out Int32 vmID, out Int64 acParent);


    [DllImport("WindowsAccessBridge-32.dll", CallingConvention = CallingConvention.Cdecl, ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)]
    private extern static void Windows_run();

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    static void Main(string[] args)
    {
        Int32 vmID = 0;
        Int64 _acParent =0;
        Windows_run();
        IntPtr hWnd = (IntPtr)FindWindow("SunAwtFrame","Standalone SwingApp");
        bool retVal = getAccessibleContextFromHWND(hWnd, out vmID, out _acParent);

    }
}

I have read a similar post but it didn't solve my issue.

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
krrishna
  • 2,050
  • 4
  • 47
  • 101
  • What are you getting for the value returned by FindWindow? You realize that the return value from FindWindow is a window *handle* (HWND), not a pointer (IntPtr)? If you're passing the HWND incorrectly, it would explain why getAccessibleContextFromHWND would return FALSE.. – David W Jul 06 '15 at 16:37
  • IntPtr is the correct type to use for pointer sized HWND – David Heffernan Jul 06 '15 at 19:03
  • Thanks for the clarification @DavidHeffernan – David W Jul 06 '15 at 19:04
  • @krrishna My guess is that you've had no answers because we don't really know what you are trying to do. If you made an MCVE and gave us clear steps to reproduce the issue then the question might be more appealing. As it stands I think we'd have to guess as to what your actual problem scenario is. – David Heffernan Jul 07 '15 at 12:25

1 Answers1

2

I got it worked. It has to do with selecting the right Target Platform combination when we are building the projects involved WindowsAccessBridge dlls. We have to try lot of permutations to get this worked.

The below link has the code but you still have to load the proper dlls to get it worked.

https://github.com/jdog3/JavaAccessBridge.Net-Sample

krrishna
  • 2,050
  • 4
  • 47
  • 101