On Thu, Feb 28, 2013 at 10:27 AM, Paul Moore <p.f.mo...@gmail.com> wrote:
> 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.

No, if the int is of the wrong size or you pass int instead of float
(but you meant float) you get nonsense or segfaults.
_______________________________________________
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