[Python-3000] Ctypes as cross-interpreter C calling interface (original) (raw)

Paul Prescod paul at prescod.net
Fri Aug 11 01:57:59 CEST 2006


And if you're curious about how to use ctypes without all of the helper functions set up for you, then I guess it is easiest to poke around the documentation for code samples.

printf.argtypes = [ccharp, ccharp, cint, cdouble] printf("String '%s', Int %d, Double %f\n", "Hi", 10, 2.2) String 'Hi', Int 10, Double 2.200000 37

from ctypes import cint, WINFUNCTYPE, windll from ctypes.wintypes import HWND, LPCSTR, UINT prototype = WINFUNCTYPE(cint, HWND, LPCSTR, LPCSTR, cuint) paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0) MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)

It's ugly but in the typical case you would hide all of the declarations in a module (maybe an auto-generated module) and just focus on your logic:

MessageBox() MessageBox(text="Spam, spam, spam") MessageBox(flags=2, text="foo bar")

Paul Prescod -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-3000/attachments/20060810/07616e7c/attachment.htm



More information about the Python-3000 mailing list