Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88997
| References | <8a777999-f941-4fcf-a924-7a8a804e158d@googlegroups.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2015-04-15 14:32 -0600 |
| Subject | Re: ctypes: using .value or .value() doesn't work for c_long |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.323.1429129996.12925.python-list@python.org> (permalink) |
On Wed, Apr 15, 2015 at 1:48 PM, IronManMark20 <mr.smittye@gmail.com> wrote: > I am using ctypes to call a few windll funcions. One of them returns a c_long object. I want to know what number the function returns. > > Problem is, when I try foo.value , it gives me this: > > AttributeError: LP_c_long object has no attribute value. > > Any idea of what could cause this? The error message indicates that this is not actually a c_long object, but an LP_c_long object; i.e., a pointer to a c_long. You can dereference the pointer using the contents attribute: >>> x = ctypes.c_long(42) >>> px = ctypes.pointer(x) >>> px <__main__.LP_c_long object at 0x7fd0812d7950> >>> px.contents c_long(42) >>> px.contents.value 42 See https://docs.python.org/3.4/library/ctypes.html#pointers for more details on working with pointers in ctypes.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ctypes: using .value or .value() doesn't work for c_long IronManMark20 <mr.smittye@gmail.com> - 2015-04-15 12:48 -0700 Re: ctypes: using .value or .value() doesn't work for c_long Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-15 14:32 -0600 Re: ctypes: using .value or .value() doesn't work for c_long Dave Angel <davea@davea.name> - 2015-04-15 17:03 -0400 Re: ctypes: using .value or .value() doesn't work for c_long ethansmithoakland@gmail.com - 2015-04-15 15:18 -0700
csiph-web