[Ann] ctypes

Thomas Heller theller at python.net
Thu Nov 7 14:59:09 EST 2002


Daily Python-URL readers have already seen this (thanks, PythonWare),
but I've fixed some problems in the first release.


ctypes is a module allowing to create and manipulate C data types in
Python. These can then be passed to C-functions loaded from dynamic
link libraries.

This module is supposed to be a greatly enhanced and much more
complete replacement of Sam Rushing's calldll/npstruct/windll
modules. ctypes is not based on Sam's work, it has different roots.

It requires Python 2.2 or higher, since it makes intensive use of the
new type system.

----

It provides classes which can be used to create complicated C data
types, for example, those used in Windows type libraries.

Included is a facility to dynamically load DLLs, retrieve functions,
and call them. You can also call methods on COM objects.

Implemented are simple data types (int, char, string, and so on),
function pointers (callbacks), structures, unions, arrays, and
pointers.

ctypes uses win32 structured exception handling, to make it as safe as
possible, although it is clear that it's easy to crash the Python
interpreter.

The source distribution contains an extensive, although inclomplete,
tutorial (which you can also read online), as well as example scripts
demonstrating the use.

One of these scripts contains a dynamic Dispatch implementation, which
is used to drive MS word as an example.

----

ctypes is not yet complete, this is an early release, but IMO it is
already entirely usable. Just don't be too astonished if later
versions have a different behaviour or api.

Homepage: http://starship.python.net/crew/theller/ctypes.html
License: BSD
Platform: Windows (32 bit Intel)

----

Have fun,

Thomas



More information about the Python-list mailing list