On 27 February 2013 23:18, Armin Rigo <ar...@tunes.org> wrote:
> from cffi import FFI
> ffi = FFI()
> ffi.cdef("""
>     int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
> """)
> lib = ffi.dlopen("USER32.DLL")
> lib.MessageBox(ffi.NULL, "Hello, world!", "Title", 0)

Yeah, that's loads better than 0.5. Presumably ffi.NULL isn't needed
and I can use 0? (After all, 0 and NULL are equivalent in C, so that's
not a correctness issue). The auto-conversion of strings is a huge
improvement.

> That's a slightly unfair example, because in this case it happens to
> work with ctypes without specifying the argtypes and the restype.  I
> would argue that this feature of ctypes is not a good thing: it's
> mostly the same as saying "you only need to declare argtypes and
> restype if you get nonsense results or segfaults".

That's a bit unfair. I'd say "you only need to declare argtypes if
you're dealing with things more complex than integers, strings and
null pointers". Which means you're fine for a huge proportion of the
Windows API.

On the other hand, going to the API level and being able to use all
the Windows constants without having to look them up (their values
aren't documented, so googling doesn't help :-() is a huge plus.

Paul.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to