Forum Stats

  • 3,838,711 Users
  • 2,262,394 Discussions
  • 7,900,739 Comments

Discussions

windowsaccessbridge problem

926649
926649 Member Posts: 2
edited Apr 9, 2013 7:18AM in Java Desktop Applications
sorry if I posted this in wrong place
These days I am researching windows access bridge (http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136191.html)
I have worked out some c# code using this tool,but now I met a problem,please help

below is my c# definition code to invoke DLL
       //
        [DllImport("WindowsAccessBridge.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern static bool getAccessibleContextInfo(int vmID, IntPtr ac, out AccessibleContextInfo textInfo);

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


       //
        [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)]
        public struct AccessibleTextItemsInfo
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
            public string letter;

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

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
            public string sentence;

        };
below is code that I extracted from this DLL's attached definition c++ file (http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136191.html)
   typedef struct AccessibleContextInfoTag {
	wchar_t name[MAX_STRING_SIZE];		// the AccessibleName of the object
	wchar_t description[MAX_STRING_SIZE];	// the AccessibleDescription of the object

	wchar_t role[SHORT_STRING_SIZE];	// localized AccesibleRole string
	wchar_t role_en_US[SHORT_STRING_SIZE];	// AccesibleRole string in the en_US locale
	wchar_t states[SHORT_STRING_SIZE];	// localized AccesibleStateSet string (comma separated)
	wchar_t states_en_US[SHORT_STRING_SIZE]; // AccesibleStateSet string in the en_US locale (comma separated)

	jint indexInParent;			// index of object in parent
	jint childrenCount;			// # of children, if any

	jint x;					// screen coords in pixels
	jint y;					// "
	jint width;				// pixel width of object
	jint height;				// pixel height of object
									
	BOOL accessibleComponent;	        // flags for various additional
	BOOL accessibleAction;			//  Java Accessibility interfaces
	BOOL accessibleSelection;		//  FALSE if this object doesn't
	BOOL accessibleText;			//  implement the additional interface
                                                //  in question

	// BOOL accessibleValue;                // old BOOL indicating whether AccessibleValue is supported
	BOOL accessibleInterfaces;		// new bitfield containing additional interface flags

    } AccessibleContextInfo;

   typedef struct AccessibleTextItemsInfoTag {
	wchar_t letter;
	wchar_t word[SHORT_STRING_SIZE];
	wchar_t sentence[MAX_STRING_SIZE];
    } AccessibleTextItemsInfo;


 
in my c# code ,using getAccessibleContextInfo is ok,but using getAccessibleTextItems always report error (read or write wrong memory),it seems to me that the reason is AccessibleTextItemsInfo structure is not properly defined in c#,so using getAccessibleTextItems cause parameter error,which result in visit wrong memory area , but according to the c++ code ,what I defined is ok,I also tried several other definition,but all error.

since from my view , there are some errors in the official DLL and its API document, for example , API Doc said you should call initializeAccessbridge before doing other things ,but there is no definition for this function in this DLL. so what I want to ask is

Can this C++ definition for this structure is wrong, so what I defined in c# did not match the implementation of the function

Hope someone could help me,Great Thanks!

Answers

This discussion has been closed.