diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2016-09-28 14:07:40 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2016-09-28 14:07:40 (GMT) |
commit | fa4a3058838c3901b571e54bd5111fb1c1f02a1e (patch) | |
tree | be21d25daffff21798393b44a7d8b83034c650a6 | |
parent | b163b14e9d9aa3badc1f3b4eb409f6a2a073f33f (diff) | |
parent | de55c612fb3176fad9dd4b17906a03baa487b5e1 (diff) | |
download | cpython-fa4a3058838c3901b571e54bd5111fb1c1f02a1e.zip cpython-fa4a3058838c3901b571e54bd5111fb1c1f02a1e.tar.gz cpython-fa4a3058838c3901b571e54bd5111fb1c1f02a1e.tar.bz2 |
Issue #21903: Merge from 3.5
-rw-r--r-- | Doc/library/ctypes.rst | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index 222773b..3db44d7 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1672,32 +1672,30 @@ different ways, depending on the type and number of the parameters in the call: The optional third item is the default value for this parameter. -This example demonstrates how to wrap the Windows ``MessageBoxA`` function so +This example demonstrates how to wrap the Windows ``MessageBoxW`` function so that it supports default parameters and named arguments. The C declaration from the windows header file is this:: WINUSERAPI int WINAPI - MessageBoxA( + MessageBoxW( HWND hWnd, - LPCSTR lpText, - LPCSTR lpCaption, + LPCWSTR lpText, + LPCWSTR lpCaption, UINT uType); Here is the wrapping with :mod:`ctypes`:: >>> from ctypes import c_int, WINFUNCTYPE, windll - >>> from ctypes.wintypes import HWND, LPCSTR, UINT - >>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT) - >>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0) - >>> MessageBox = prototype(("MessageBoxA", windll.user32), paramflags) - >>> + >>> from ctypes.wintypes import HWND, LPCWSTR, UINT + >>> prototype = WINFUNCTYPE(c_int, HWND, LPCWSTR, LPCWSTR, UINT) + >>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", "Hello from ctypes"), (1, "flags", 0) + >>> MessageBox = prototype(("MessageBoxW", windll.user32), paramflags) -The MessageBox foreign function can now be called in these ways:: +The ``MessageBox`` foreign function can now be called in these ways:: >>> MessageBox() >>> MessageBox(text="Spam, spam, spam") >>> MessageBox(flags=2, text="foo bar") - >>> A second example demonstrates output parameters. The win32 ``GetWindowRect`` function retrieves the dimensions of a specified window by copying them into |