ctypes for IronPython (preliminary)

Sanghyeon Seo sanxiyn at gmail.com
Thu Jun 8 01:00:23 EDT 2006


ctypes is a popular CPython extension planned for inclusion in Python
2.5. It is a foreign function interface library.

Homepage: http://starship.python.net/crew/theller/ctypes/
Documentation: http://docs.python.org/dev/lib/module-ctypes.html

I would like to announce a preliminary implementation of ctypes for
IronPython using .NET's P/Invoke machinery.

Code is here: http://sparcs.kaist.ac.kr/~tinuviel/fepy/lib/ctypes.py
Example is here: http://sparcs.kaist.ac.kr/~tinuviel/fepy/example/ctypes_test.py

The example can be run on IronPython as well as on CPython.

What's missing:
* Many primitive types
* .value on primitive types
* Buffers and .raw
* Pointer and .contents
* Reference
* Array
* Structure and union and .offset
* Recursive type
* Callback
* External value
* Windows goodies

In short, everything except those needed to demo anything interesting.
:-) But you can do this now:

IronPython 1.0.60523 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> from ctypes import *
>>> print cdll.msvcrt.strlen('hello')
5
>>>

Enjoy!

Seo Sanghyeon



More information about the Python-list mailing list