Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa4a305

Browse files
committed
Issue #21903: Merge from 3.5
2 parents b163b14 + de55c61 commit fa4a305

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

Doc/library/ctypes.rst

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,32 +1672,30 @@ different ways, depending on the type and number of the parameters in the call:
16721672

16731673
The optional third item is the default value for this parameter.
16741674

1675-
This example demonstrates how to wrap the Windows ``MessageBoxA`` function so
1675+
This example demonstrates how to wrap the Windows ``MessageBoxW`` function so
16761676
that it supports default parameters and named arguments. The C declaration from
16771677
the windows header file is this::
16781678

16791679
WINUSERAPI int WINAPI
1680-
MessageBoxA(
1680+
MessageBoxW(
16811681
HWND hWnd,
1682-
LPCSTR lpText,
1683-
LPCSTR lpCaption,
1682+
LPCWSTR lpText,
1683+
LPCWSTR lpCaption,
16841684
UINT uType);
16851685

16861686
Here is the wrapping with :mod:`ctypes`::
16871687

16881688
>>> from ctypes import c_int, WINFUNCTYPE, windll
1689-
>>> from ctypes.wintypes import HWND, LPCSTR, UINT
1690-
>>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
1691-
>>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)
1692-
>>> MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)
1693-
>>>
1689+
>>> from ctypes.wintypes import HWND, LPCWSTR, UINT
1690+
>>> prototype = WINFUNCTYPE(c_int, HWND, LPCWSTR, LPCWSTR, UINT)
1691+
>>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", "Hello from ctypes"), (1, "flags", 0)
1692+
>>> MessageBox = prototype(("MessageBoxW", windll.user32), paramflags)
16941693

1695-
The MessageBox foreign function can now be called in these ways::
1694+
The ``MessageBox`` foreign function can now be called in these ways::
16961695

16971696
>>> MessageBox()
16981697
>>> MessageBox(text="Spam, spam, spam")
16991698
>>> MessageBox(flags=2, text="foo bar")
1700-
>>>
17011699

17021700
A second example demonstrates output parameters. The win32 ``GetWindowRect``
17031701
function retrieves the dimensions of a specified window by copying them into

0 commit comments

Comments
 (0)