Questions about pointers
"Massi" <[email protected]> Sat, 25 May 2013 16:38:01 +0200
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Hi everyone,
I’m starting to use ctypes pointer in my applications ad I have some doubts.
Consider this scenario.
lib = cdll.LoadLibrary(“MyLib.dll”)
c = POINTER(c_int)()
lib.MyAllocInt(byref(c), c_int(10))
Then ‘c’ is allocated and it contains 10 integers. Now if I do the following:
print c[0]
I get 0 while I expect c_int(0), can anyone explain me this?
Furthermore this creates me a problem. Let’s consider this example, in which I want ‘c’ to be filled with the output of a given function:
for i in range(10):
lib.MyFunction(c_int(i), c_int(i+1), byref(c[i]))
I get an error since byref() expects a c_int, while c[i] is an integer. So I have to do:
for i in range(10):
t = c_int(0)
lib.MyFunction(c_int(i), c_int(i+1), byref(t))
c[i] = t.value
which is pretty .uncomfortable. Is there a smarter way to achieve this? Thanks in advance!
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users