Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a596f778
Commit
a596f778
authored
Sep 28, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21903: Update ctypes example to use MessageBoxW
parent
b91db550
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
+9
-11
Doc/library/ctypes.rst
Doc/library/ctypes.rst
+9
-11
No files found.
Doc/library/ctypes.rst
View file @
a596f778
...
...
@@ -1665,32 +1665,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 ``MessageBox
A
`` function so
This example demonstrates how to wrap the Windows ``MessageBox
W
`` function so
that it supports default parameters and named arguments. The C declaration from
the windows header file is this::
WINUSERAPI int WINAPI
MessageBox
A
(
MessageBox
W
(
HWND hWnd,
LPCSTR lpText,
LPCSTR lpCaption,
LPC
W
STR lpText,
LPC
W
STR 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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment