I have a trouble with using ctypes lib in my python script. Here is my code (found on the Internet):
if __name__ == \"__main__\":
from ctypes import *
Ok, thx dudes! I just reconfig my NetBeans, now its using cPython. Everything works. I just had to changed the line
user32.SetCursorPos(windowRect.left + x, windowRect.top + y)
to:
user32.SetCursorPos(c_ulong(windowRect.left + x), c_ulong(windowRect.left + y))
Jython doesn't yet have full support for ctypes: http://bugs.jython.org/issue1328
You can't simply take the ctypes library compiled for CPython, and plug it into Jython.
ctypes
in Jython experimental and not complete.
From the jython-users mailing list in a thread titled "ctypes in Jython" Jim Baker (a Jython committer) wrote on November 17, 2010:
There's some experimental support for ctypes in 2.5.2 [the current version], but it's really more of a placeholder at this point.
He then suggests these work arounds:
I do recommend JNA if you can modify your ctypes code. JNA is pretty close to ctypes - JNA's API apparently was significantly influenced by ctypes! JNA also seems to work well with Jython.
The other option is to use something like execnet. For execnet specifically: it allows you to pair Jython with CPython, and it does seem to work well. But its GPL license makes it a non starter for many people. There are other choices out there too.
Further on in the same thread we have this confirming assessment:
I tried the ctypes module in 2.5.2rc2 recently, and found that: 1) There's no ctypes.util.find_library yet 2) ctypes.Structure doesn't support non-scalar types yet
So I agree with the "more of a placeholder" assessment. Still, it's exciting to see it getting started.
ctypes is not supported in Jython 2.5.1. There has been some experimental support added in 2.5.2, but it's certainly nowhere near complete. Maybe you'll have better luck using JNA with Jython instead. There's a short tutorial here.