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
e2c069bb
Commit
e2c069bb
authored
Sep 28, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Plain Diff
Issue #21903: Merge from 3.5
parents
596d66a0
a596f778
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 @
e2c069bb
...
...
@@ -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 ``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