Pointers in Structures
Guy Rozendorn <[email protected]> Wed, 16 Nov 2011 12:58:14 +0200
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Hello all,
I have a question about setting pointers within structures.
This is what I had in mind:
from binascii import *
from ctypes import *
class MyStruct(Structure):
_fields_ = [("foo", c_uint), ("bar", POINTER(c_uint))]
But, as you can see below, setting s.bar does not change the memory
content of s:
In [2]: s = MyStruct()
In [3]: byref(s)
Out[3]: <cparam 'P' (0x101e346d0)>
In [4]: hexlify(string_at(0x101e346d0, 8))
Out[4]: '0000000000000000'
In [5]: x = c_uint(1)
In [6]: p = pointer(x)
In [7]: s.foo = x
In [8]: s.bar = p
In [9]: hexlify(string_at(0x101e346d0, 8))
Out[9]: '0100000000000000'
What am I doing wrong?
Thanks,
Guy
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users