My hunch was correct, the problems was with incorrect argument when calling GetWindowText(). It suppose to be char[]
- not a Jython variable. This lead me to research more and find something I wasn't aware before - Java arrays in Jython. As stated in Jython documentation http://www.jython.org/archive/21/docs/jarray.html :
Many Java methods require Java array objects as arguments. The way that these arguments are used means that they must correspond to fixed-length, mutable sequences, sometimes of primitive data types. The PyArray class is added to support these Java arrays and instances of this class will be automatically returned from any Java method call that produces an array. In addition, the "jarray" module is provided to allow users of Jython to create these arrays themselves, primarily for the purpose of passing them to a Java method.
The documentation has the mapping table as well. The working code would be something like this:
import jarray
text_length = User32.INSTANCE.GetWindowTextLength(handle)
max_length = 512
text = jarray.zeros(text_length, 'c')
result = User32.INSTANCE.GetWindowText(handle, text, max_length)
print 'Copied text:', result