Click here to Skip to main content
15,885,164 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
We are using the Java Access Bridge (windows access bridge DLL) in trying to send text to a java window’s fields. We have initialized the A.P.I., successfully detected a java window (this only works correctly on the second call to the “isJavaWindow” function). We are able to obtain the accessible context via “getAccessibleContextFromHWND”. We then use the context to recurse through the children until we find the text box in question. We are able to use “getTextInfo” function to read the contents of the field and the “getAccessibleContextInfo” function is returning good data. I can see that the property of the field is editable via the accessibleContextInfo data structure, however the “setTextContents” function always returns false. Here is the code snippet usage in C# (we have also tried using Autoit) A.P.I. version 2.0.2

C#
public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }

          private void button1_Click(object sender, EventArgs e)
          {
                // enumerate the windows
                JavaAPIFunc.Windows_run();
                bool found = false;
                
                Int32 VmId = 0;
                AccessibleContext Ac = new AccessibleContext();
                AccessibleContextInfo Info = new AccessibleContextInfo();
                foreach (KeyValuePair<intptr,> lWindow in OpenWindowGetter.GetOpenWindows())
                {
                    IntPtr lHandle = lWindow.Key;
                    string lTitle = lWindow.Value;
                    if (JavaAPIFunc.isJavaWindow((HWND)lHandle))
                    {
                        MessageBox.Show("Found a java window");
                        JavaAPIFunc.getAccessibleContextFromHWND(lHandle, out VmId, out Ac);
                        found = true;
                        break;
                    }
                }

            if(found)
            {
                TraverseTheBullshitInterface(VmId, Ac);
            }
        }

        private AccessibleContext TraverseTheBullshitInterface(Int32 VmId ,AccessibleContext AccessContext)
        {
            AccessibleContextInfo Info = new AccessibleContextInfo();
            AccessibleTextItemsInfo TextInfo = new AccessibleTextItemsInfo();
            JavaAPIFunc.getAccessibleContextInfo(VmId, AccessContext, ref Info);
            
            if (Info.name == "User name:" && Info.role_en_US == "text")
            {
                 JavaAPIFunc.getAccessibleTextItems(VmId, AccessContext, ref TextInfo, 0);
                if(!JavaAPIFunc.setTextContents(VmId, AccessContext, "test"))
                {
                     throw new Exception("Error setting text");
                }
            }

            for (int i = 0; i < Info.childrenCount; ++i)
            {
                TraverseTheBullshitInterface(VmId,JavaAPIFunc.getAccessibleChildFromContext(VmId, AccessContext, i));
            }
            return AccessContext;
        }
    }

data structures:
<pre lang="cs">public enum WABAPI { MAX_STRING_SIZE = 1024, SHORT_STRING_SIZE = 256, MAX_BUFFER_SIZE = 10240 }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleContextInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]
public string name;          // the AccessibleName of the object
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]
public string description;     // the AccessibleDescription of the object
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public string role;     // localized AccesibleRole string
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public string role_en_US;     // AccesibleRole string in the en_US locale
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public string states;     // localized AccesibleStateSet string (comma separated)
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public string states_en_US; // AccesibleStateSet string in the en_US locale (comma separated)

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

public Int32 x;                         // screen coords in pixels
public Int32 y;                         // "
public Int32 width;                    // pixel width of object
public Int32 height;                    // pixel height of object

public Boolean accessibleComponent;     // flags for various additional
public Boolean accessibleAction;               // Java Accessibility interfaces
public Boolean accessibleSelection;          // FALSE if this object doesn't
public Boolean accessibleText;               // implement the additional interface
// in question

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

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleTextInfo
{
public Int32 charCount;                              // # of characters in this text object
public Int32 caretIndex;                         // index of caret
public Int32 indexAtPoint;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleTextItemsInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
public String letter;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public String word;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]
public String sentence;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleTextAttributesInfo
{
public Boolean bold;
public Boolean italic;
public Boolean underline;
public Boolean strikethrough;
public Boolean superscript;
public Boolean subscript;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public String backgroundColor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public String foregroundColor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]
public String fontFamily;
public Int32 fontSize;

public Int32 alignment;
public Int32 bidiLevel;

public Single firstLineIndent;
public Single leftIndent;
public Single rightIndent;
public Single lineSpacing;
public Single spaceAbove;
public Single spaceBelow;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]
public String fullAttributesString;
}

Prototype import:

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("WindowsAccessBridge-64.dll", CallingConvention = CallingConvention.Cdecl,        ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)]
        public extern static bool setTextContents(Int32 vmID, AccessibleContext accessibleContext, string text);
Posted
Updated 8-Feb-23 20:14pm
v3
Comments
Richard MacCutchan 8-Jul-14 9:01am    
Well you need to expalin where in your code the failure occurs.
Richard MacCutchan 8-Jul-14 10:23am    
And what does that tell us that will help to figure out why?
||ok|| 29-Jun-17 10:08am    
I'm having the same problem - everything else works, but SetTextContents always returns false - were you ever able to get this to work? (I tried the solution below, but it doesn't work).

XML
<pre lang="c#">        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("WindowsAccessBridge-64.dll", CallingConvention = CallingConvention.Cdecl,        ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)]
        public extern static bool setTextContents(Int32 vmID, AccessibleContext accessibleContext, string text);
</pre>

Should be:

<pre lang="c#">        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("WindowsAccessBridge-64.dll", CallingConvention = CallingConvention.Cdecl,        ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)]
        public extern static bool setTextContents(Int32 vmID, <b>IntPtr accessibleContext</b>, string text);</pre>
 
Share this answer
 
I am trying to automate Oracle form Java Applet using Java Access Bridge through c#. I am able to get value from text field, click on buttons but setTextContents is not working. This is always giving false response only for Oracle form Java Applet.

Any idea/alternate solution? Please help me to understand what is blocking to set text in Oracle form Java Applet.

my code snippet :

if (!JabApi.setTextContents(vmID, txt.acPtr, "Test Data"))
{
throw new Exception("Error setting text");
}
 
Share this answer
 
Comments
Richard Deeming 9-Feb-23 4:13am    
Your question is not a "solution" to someone else's question.

If you want to ask a question, then ASK A QUESTION[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900