32-bit Java Accessibility on a 64-bit machine

后端 未结 3 1245
臣服心动
臣服心动 2021-02-10 12:38

I have a 32-bit app that makes use of Java Accessibility (WindowsAccessBridge-32.dll, via the Java Access Bridge), and works perfectly on a 32-bit machine, but fails on an x64 m

相关标签:
3条回答
  • 2021-02-10 13:16

    If your using a 64 bit JVM with a 32 bit version of the Java Access bridge it won't work correctly. You need a 64 bit version of the access bridge which has recently been released. see http://blogs.oracle.com/korn/entry/java_access_bridge_v2_0 For instructions on installing a 32 bit copy of the access bridge for use with 32 bit JRE's under 64 bit windows see http://www.travisroth.com/2009/07/03/java-access-bridge-and-64-bit-windows/

    0 讨论(0)
  • 2021-02-10 13:27

    The call to 'initializeAccessBridge' REQUIRES you to have an active windows message pump. Inside 'initializeAccessBridge', it (eventually) creates a hidden dialog window (using CreateDialog). Once the dialog is created, it performs a PostMessage with a registered message. The JavaVM side of the access bridge responds to this message, and posts back another message to the dialog that was created (it appears to be a 'hello' type handshake between your app and the java VM). As such, if your application doesn't have an active message pump, the return message from the JavaVM never gets received by your app.

    0 讨论(0)
  • 2021-02-10 13:33

    It appears that the problem is in the type of AccessibilityContext:

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

    AccessibilityContext (acParent above), which I had incorrectly mapped as an IntPtr, is actually an Int32 when using the "legacy" WindowsAccessBridge.dll library (used under x86), and an Int64 when using the WOW64 WindowsAccessBridge-32.dll library.

    So the upshot is, the code has to differ between x86 and WOW x64, and must be compiled separately for each. I do this by #define'ing WOW64 during x64 builds, always referencing the Int64 methods, and using "shim" methods on x86:

    #if WOW64 // using x64
    
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("WindowsAccessBridge-32.dll", CallingConvention = CallingConvention.Cdecl)]
    public extern static bool getAccessibleContextFromHWND(IntPtr hwnd, out Int32 vmID, out Int64 acParent);
    
    #else // using x86
    
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("WindowsAccessBridge.dll", EntryPoint = "getAccessibleContextFromHWND", CallingConvention = CallingConvention.Cdecl)]
    private extern static bool _getAccessibleContextFromHWND(IntPtr hwnd, out Int32 vmID, out Int32 acParent);
    
    public static bool getAccessibleContextFromHWND(IntPtr hwnd, out Int32 vmID, out Int64 acParent)
    {
      Int32 _acParent;
    
      bool retVal = _getAccessibleContextFromHWND(hwnd, out vmID, out _acParent);
      acParent = _acParent;
    
      return retVal;
    }
    
    #endif
    
    0 讨论(0)
提交回复
热议问题