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

Skip to content

Commit de55c61

Browse files
committed
Issue #21903: Update ctypes example to use MessageBoxW
1 parent 0c6974d commit de55c61

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
@@ -1665,32 +1665,30 @@ different ways, depending on the type and number of the parameters in the call:
16651665

16661666
The optional third item is the default value for this parameter.
16671667

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

16721672
WINUSERAPI int WINAPI
1673-
MessageBoxA(
1673+
MessageBoxW(
16741674
HWND hWnd,
1675-
LPCSTR lpText,
1676-
LPCSTR lpCaption,
1675+
LPCWSTR lpText,
1676+
LPCWSTR lpCaption,
16771677
UINT uType);
16781678

16791679
Here is the wrapping with :mod:`ctypes`::
16801680

16811681
>>> from ctypes import c_int, WINFUNCTYPE, windll
1682-
>>> from ctypes.wintypes import HWND, LPCSTR, UINT
1683-
>>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
1684-
>>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)
1685-
>>> MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)
1686-
>>>
1682+
>>> from ctypes.wintypes import HWND, LPCWSTR, UINT
1683+
>>> prototype = WINFUNCTYPE(c_int, HWND, LPCWSTR, LPCWSTR, UINT)
1684+
>>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", "Hello from ctypes"), (1, "flags", 0)
1685+
>>> MessageBox = prototype(("MessageBoxW", windll.user32), paramflags)
16871686

1688-
The MessageBox foreign function can now be called in these ways::
1687+
The ``MessageBox`` foreign function can now be called in these ways::
16891688

16901689
>>> MessageBox()
16911690
>>> MessageBox(text="Spam, spam, spam")
16921691
>>> MessageBox(flags=2, text="foo bar")
1693-
>>>
16941692

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

0 commit comments

Comments
 (0)