_SimpleCData
is a subclass of _CData
, so it inherits their methods and
attributes.
Instances have a single attribute:
When the value
attribute is retrieved from a ctypes instance,
usually a new object is returned each time. ctypes
does not
implement original object return, always a new object is
constructed. The same is true for all other ctypes object
instances.
Fundamental data types, when returned as foreign function call results, or, for example, by retrieving structure field members or array items, are transparently converted to native Python types. In other words, if a foreign function has a restype of c_char_p, you will always receive a Python string, not a c_char_p instance.
Subclasses of fundamental data types do not inherit this behaviour.
So, if a foreign functions restype is a subclass of c_void_p,
you will receive an instance of this subclass from the function call.
Of course, you can get the value of the pointer by accessing the
value
attribute.
These are the fundamental ctypes data types:
sizeof(int) == sizeof(long)
it is an alias to
c_long.
signed int
datatype. Usually an alias for
c_byte.
signed int
datatype. Usually an alias
for c_longlong.
signed long
datatype. The constructor accepts an
optional integer initializer; no overflow checking is done.
signed long long
datatype. The constructor accepts
an optional integer initializer; no overflow checking is done.
signed short
datatype. The constructor accepts an
optional integer initializer; no overflow checking is done.
size_t
datatype.
unsigned char
datatype, it interprets the
value as small integer. The constructor accepts an optional
integer initializer; no overflow checking is done.
unsigned int
datatype. The constructor accepts an
optional integer initializer; no overflow checking is done. On
platforms where sizeof(int) == sizeof(long)
it is an alias for
c_ulong.
unsigned long
datatype. The constructor accepts an
optional integer initializer; no overflow checking is done.
unsigned long long
datatype. The constructor
accepts an optional integer initializer; no overflow checking is
done.
unsigned short
datatype. The constructor accepts an
optional integer initializer; no overflow checking is done.
void *
type. The value is represented as
integer. The constructor accepts an optional integer initializer.
wchar_t
datatype, and interprets the value as a
single character unicode string. The constructor accepts an
optional string initializer, the length of the string must be
exactly one character.
wchar_t *
datatype, which must be a pointer to
a zero-terminated wide character string. The constructor accepts
an integer address, or a string.
PyObject *
datatype. Calling this without an
argument creates a NULL
PyObject *
pointer.
The ctypes.wintypes
module provides quite some other Windows
specific data types, for example HWND
, WPARAM
, or DWORD
.
Some useful structures like MSG
or RECT
are also defined.
See About this document... for information on suggesting changes.