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
cc868d43
Commit
cc868d43
authored
Sep 28, 2010
by
Hirokazu Yamamoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #3612: Added new types to ctypes.wintypes. (CHAR and pointers)
parent
7405c200
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
74 deletions
+97
-74
Lib/ctypes/wintypes.py
Lib/ctypes/wintypes.py
+95
-74
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/ctypes/wintypes.py
View file @
cc868d43
# The most useful windows datatypes
from
ctypes
import
*
import
ctypes
BYTE
=
c_byte
WORD
=
c_ushort
DWORD
=
c_ulong
BYTE
=
c
types
.
c
_byte
WORD
=
c
types
.
c
_ushort
DWORD
=
c
types
.
c
_ulong
WCHAR
=
c_wchar
UINT
=
c_uint
INT
=
c_int
#UCHAR = ctypes.c_uchar
CHAR
=
ctypes
.
c_char
WCHAR
=
ctypes
.
c_wchar
UINT
=
ctypes
.
c_uint
INT
=
ctypes
.
c_int
DOUBLE
=
c_double
FLOAT
=
c_float
DOUBLE
=
c
types
.
c
_double
FLOAT
=
c
types
.
c
_float
BOOLEAN
=
BYTE
BOOL
=
c_long
BOOL
=
c
types
.
c
_long
from
ctypes
import
_SimpleCData
class
VARIANT_BOOL
(
_SimpleCData
):
class
VARIANT_BOOL
(
ctypes
.
_SimpleCData
):
_type_
=
"v"
def
__repr__
(
self
):
return
"%s(%r)"
%
(
self
.
__class__
.
__name__
,
self
.
value
)
ULONG
=
c_ulong
LONG
=
c_long
ULONG
=
c
types
.
c
_ulong
LONG
=
c
types
.
c
_long
USHORT
=
c_ushort
SHORT
=
c_short
USHORT
=
c
types
.
c
_ushort
SHORT
=
c
types
.
c
_short
# in the windows header files, these are structures.
_LARGE_INTEGER
=
LARGE_INTEGER
=
c_longlong
_ULARGE_INTEGER
=
ULARGE_INTEGER
=
c_ulonglong
_LARGE_INTEGER
=
LARGE_INTEGER
=
c
types
.
c
_longlong
_ULARGE_INTEGER
=
ULARGE_INTEGER
=
c
types
.
c
_ulonglong
LPCOLESTR
=
LPOLESTR
=
OLESTR
=
c_wchar_p
LPCWSTR
=
LPWSTR
=
c_wchar_p
LPCSTR
=
LPSTR
=
c_char_p
LPCVOID
=
LPVOID
=
c_void_p
LPCOLESTR
=
LPOLESTR
=
OLESTR
=
c
types
.
c
_wchar_p
LPCWSTR
=
LPWSTR
=
c
types
.
c
_wchar_p
LPCSTR
=
LPSTR
=
c
types
.
c
_char_p
LPCVOID
=
LPVOID
=
c
types
.
c
_void_p
# WPARAM is defined as UINT_PTR (unsigned type)
# LPARAM is defined as LONG_PTR (signed type)
if
sizeof
(
c_long
)
==
sizeof
(
c_void_p
):
WPARAM
=
c_ulong
LPARAM
=
c_long
elif
sizeof
(
c_longlong
)
==
sizeof
(
c_void_p
):
WPARAM
=
c_ulonglong
LPARAM
=
c_longlong
if
ctypes
.
sizeof
(
ctypes
.
c_long
)
==
ctypes
.
sizeof
(
ctypes
.
c_void_p
):
WPARAM
=
c
types
.
c
_ulong
LPARAM
=
c
types
.
c
_long
elif
ctypes
.
sizeof
(
ctypes
.
c_longlong
)
==
ctypes
.
sizeof
(
ctypes
.
c_void_p
):
WPARAM
=
c
types
.
c
_ulonglong
LPARAM
=
c
types
.
c
_longlong
ATOM
=
WORD
LANGID
=
WORD
...
...
@@ -56,7 +57,7 @@ LCID = DWORD
################################################################
# HANDLE types
HANDLE
=
c_void_p
# in the header files: void *
HANDLE
=
c
types
.
c
_void_p
# in the header files: void *
HACCEL
=
HANDLE
HBITMAP
=
HANDLE
...
...
@@ -93,45 +94,45 @@ SERVICE_STATUS_HANDLE = HANDLE
################################################################
# Some important structure definitions
class
RECT
(
Structure
):
_fields_
=
[(
"left"
,
c_long
),
(
"top"
,
c_long
),
(
"right"
,
c_long
),
(
"bottom"
,
c_long
)]
class
RECT
(
ctypes
.
Structure
):
_fields_
=
[(
"left"
,
LONG
),
(
"top"
,
LONG
),
(
"right"
,
LONG
),
(
"bottom"
,
LONG
)]
tagRECT
=
_RECTL
=
RECTL
=
RECT
class
_SMALL_RECT
(
Structure
):
_fields_
=
[(
'Left'
,
c_short
),
(
'Top'
,
c_short
),
(
'Right'
,
c_short
),
(
'Bottom'
,
c_short
)]
class
_SMALL_RECT
(
ctypes
.
Structure
):
_fields_
=
[(
'Left'
,
SHORT
),
(
'Top'
,
SHORT
),
(
'Right'
,
SHORT
),
(
'Bottom'
,
SHORT
)]
SMALL_RECT
=
_SMALL_RECT
class
_COORD
(
Structure
):
_fields_
=
[(
'X'
,
c_short
),
(
'Y'
,
c_short
)]
class
_COORD
(
ctypes
.
Structure
):
_fields_
=
[(
'X'
,
SHORT
),
(
'Y'
,
SHORT
)]
class
POINT
(
Structure
):
_fields_
=
[(
"x"
,
c_long
),
(
"y"
,
c_long
)]
class
POINT
(
ctypes
.
Structure
):
_fields_
=
[(
"x"
,
LONG
),
(
"y"
,
LONG
)]
tagPOINT
=
_POINTL
=
POINTL
=
POINT
class
SIZE
(
Structure
):
_fields_
=
[(
"cx"
,
c_long
),
(
"cy"
,
c_long
)]
class
SIZE
(
ctypes
.
Structure
):
_fields_
=
[(
"cx"
,
LONG
),
(
"cy"
,
LONG
)]
tagSIZE
=
SIZEL
=
SIZE
def
RGB
(
red
,
green
,
blue
):
return
red
+
(
green
<<
8
)
+
(
blue
<<
16
)
class
FILETIME
(
Structure
):
class
FILETIME
(
ctypes
.
Structure
):
_fields_
=
[(
"dwLowDateTime"
,
DWORD
),
(
"dwHighDateTime"
,
DWORD
)]
_FILETIME
=
FILETIME
class
MSG
(
Structure
):
class
MSG
(
ctypes
.
Structure
):
_fields_
=
[(
"hWnd"
,
HWND
),
(
"message"
,
c_uint
),
(
"message"
,
UINT
),
(
"wParam"
,
WPARAM
),
(
"lParam"
,
LPARAM
),
(
"time"
,
DWORD
),
...
...
@@ -139,7 +140,7 @@ class MSG(Structure):
tagMSG
=
MSG
MAX_PATH
=
260
class
WIN32_FIND_DATAA
(
Structure
):
class
WIN32_FIND_DATAA
(
ctypes
.
Structure
):
_fields_
=
[(
"dwFileAttributes"
,
DWORD
),
(
"ftCreationTime"
,
FILETIME
),
(
"ftLastAccessTime"
,
FILETIME
),
...
...
@@ -148,10 +149,10 @@ class WIN32_FIND_DATAA(Structure):
(
"nFileSizeLow"
,
DWORD
),
(
"dwReserved0"
,
DWORD
),
(
"dwReserved1"
,
DWORD
),
(
"cFileName"
,
c_char
*
MAX_PATH
),
(
"cAlternateFileName"
,
c_char
*
14
)]
(
"cFileName"
,
CHAR
*
MAX_PATH
),
(
"cAlternateFileName"
,
CHAR
*
14
)]
class
WIN32_FIND_DATAW
(
Structure
):
class
WIN32_FIND_DATAW
(
ctypes
.
Structure
):
_fields_
=
[(
"dwFileAttributes"
,
DWORD
),
(
"ftCreationTime"
,
FILETIME
),
(
"ftLastAccessTime"
,
FILETIME
),
...
...
@@ -160,22 +161,42 @@ class WIN32_FIND_DATAW(Structure):
(
"nFileSizeLow"
,
DWORD
),
(
"dwReserved0"
,
DWORD
),
(
"dwReserved1"
,
DWORD
),
(
"cFileName"
,
c_wchar
*
MAX_PATH
),
(
"cAlternateFileName"
,
c_wchar
*
14
)]
__all__
=
[
'ATOM'
,
'BOOL'
,
'BOOLEAN'
,
'BYTE'
,
'COLORREF'
,
'DOUBLE'
,
'DWORD'
,
'FILETIME'
,
'FLOAT'
,
'HACCEL'
,
'HANDLE'
,
'HBITMAP'
,
'HBRUSH'
,
'HCOLORSPACE'
,
'HDC'
,
'HDESK'
,
'HDWP'
,
'HENHMETAFILE'
,
'HFONT'
,
'HGDIOBJ'
,
'HGLOBAL'
,
'HHOOK'
,
'HICON'
,
'HINSTANCE'
,
'HKEY'
,
'HKL'
,
'HLOCAL'
,
'HMENU'
,
'HMETAFILE'
,
'HMODULE'
,
'HMONITOR'
,
'HPALETTE'
,
'HPEN'
,
'HRGN'
,
'HRSRC'
,
'HSTR'
,
'HTASK'
,
'HWINSTA'
,
'HWND'
,
'INT'
,
'LANGID'
,
'LARGE_INTEGER'
,
'LCID'
,
'LCTYPE'
,
'LGRPID'
,
'LONG'
,
'LPARAM'
,
'LPCOLESTR'
,
'LPCSTR'
,
'LPCVOID'
,
'LPCWSTR'
,
'LPOLESTR'
,
'LPSTR'
,
'LPVOID'
,
'LPWSTR'
,
'MAX_PATH'
,
'MSG'
,
'OLESTR'
,
'POINT'
,
'POINTL'
,
'RECT'
,
'RECTL'
,
'RGB'
,
'SC_HANDLE'
,
'SERVICE_STATUS_HANDLE'
,
'SHORT'
,
'SIZE'
,
'SIZEL'
,
'SMALL_RECT'
,
'UINT'
,
'ULARGE_INTEGER'
,
'ULONG'
,
'USHORT'
,
'VARIANT_BOOL'
,
'WCHAR'
,
'WIN32_FIND_DATAA'
,
'WIN32_FIND_DATAW'
,
'WORD'
,
'WPARAM'
,
'_COORD'
,
'_FILETIME'
,
'_LARGE_INTEGER'
,
'_POINTL'
,
'_RECTL'
,
'_SMALL_RECT'
,
'_ULARGE_INTEGER'
,
'tagMSG'
,
'tagPOINT'
,
'tagRECT'
,
'tagSIZE'
]
(
"cFileName"
,
WCHAR
*
MAX_PATH
),
(
"cAlternateFileName"
,
WCHAR
*
14
)]
################################################################
# Pointer types
LPBOOL
=
PBOOL
=
ctypes
.
POINTER
(
BOOL
)
PBOOLEAN
=
ctypes
.
POINTER
(
BOOLEAN
)
LPBYTE
=
PBYTE
=
ctypes
.
POINTER
(
BYTE
)
PCHAR
=
ctypes
.
POINTER
(
CHAR
)
LPCOLORREF
=
ctypes
.
POINTER
(
COLORREF
)
LPDWORD
=
PDWORD
=
ctypes
.
POINTER
(
DWORD
)
LPFILETIME
=
PFILETIME
=
ctypes
.
POINTER
(
FILETIME
)
PFLOAT
=
ctypes
.
POINTER
(
FLOAT
)
LPHANDLE
=
PHANDLE
=
ctypes
.
POINTER
(
HANDLE
)
PHKEY
=
ctypes
.
POINTER
(
HKEY
)
LPHKL
=
ctypes
.
POINTER
(
HKL
)
LPINT
=
PINT
=
ctypes
.
POINTER
(
INT
)
PLARGE_INTEGER
=
ctypes
.
POINTER
(
LARGE_INTEGER
)
PLCID
=
ctypes
.
POINTER
(
LCID
)
LPLONG
=
PLONG
=
ctypes
.
POINTER
(
LONG
)
LPMSG
=
PMSG
=
ctypes
.
POINTER
(
MSG
)
LPPOINT
=
PPOINT
=
ctypes
.
POINTER
(
POINT
)
PPOINTL
=
ctypes
.
POINTER
(
POINTL
)
LPRECT
=
PRECT
=
ctypes
.
POINTER
(
RECT
)
LPRECTL
=
PRECTL
=
ctypes
.
POINTER
(
RECTL
)
LPSC_HANDLE
=
ctypes
.
POINTER
(
SC_HANDLE
)
PSHORT
=
ctypes
.
POINTER
(
SHORT
)
LPSIZE
=
PSIZE
=
ctypes
.
POINTER
(
SIZE
)
LPSIZEL
=
PSIZEL
=
ctypes
.
POINTER
(
SIZEL
)
PSMALL_RECT
=
ctypes
.
POINTER
(
SMALL_RECT
)
LPUINT
=
PUINT
=
ctypes
.
POINTER
(
UINT
)
PULARGE_INTEGER
=
ctypes
.
POINTER
(
ULARGE_INTEGER
)
PULONG
=
ctypes
.
POINTER
(
ULONG
)
PUSHORT
=
ctypes
.
POINTER
(
USHORT
)
PWCHAR
=
ctypes
.
POINTER
(
WCHAR
)
LPWIN32_FIND_DATAA
=
PWIN32_FIND_DATAA
=
ctypes
.
POINTER
(
WIN32_FIND_DATAA
)
LPWIN32_FIND_DATAW
=
PWIN32_FIND_DATAW
=
ctypes
.
POINTER
(
WIN32_FIND_DATAW
)
LPWORD
=
PWORD
=
ctypes
.
POINTER
(
WORD
)
Misc/NEWS
View file @
cc868d43
...
...
@@ -74,6 +74,8 @@ Core and Builtins
Library
-------
- Issue #3612: Added new types to ctypes.wintypes. (CHAR and pointers)
- Issue #9950: Fix socket.sendall() crash or misbehaviour when a signal is
received. Now sendall() properly calls signal handlers if necessary,
and retries sending if these returned successfully, including on sockets
...
...
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