This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: wintypes.SIZE is 8bytes on 32 bit machines
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, nnstein
Priority: normal Keywords:

Created on 2021-02-08 21:02 by nnstein, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg386666 - (view) Author: Noah Steinberg (nnstein) Date: 2021-02-08 21:02
Noticed while debugging a problem with a test running on Windows 10 x86 that sizeof(wintypes.SIZE)==8 when I believe it should be 4. While using 

kernel32.CreateRemoteThread.argtypes = [wintypes.HANDLE, wintypes.LPCVOID, wintypes.DWORD, wintypes.LPCVOID, wintypes.LPCVOID, wintypes.DWORD, wintypes.LPDWORD] 

and  

kernel32.CreateRemoteThread(h_process, 0, 0, 0xbadadd, 0, 4, byref(thread_id))

It caused CreateRemoteThread to recieve 4 as the last argument, resulting in an access denied
msg386670 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-02-08 23:04
The SIZE [1] type for a rectangle has nothing to do with SIZE_T [2], the integer type that's returned by C sizeof(). SIZE_T isn't defined in wintypes. A new issue can be opened to add more of the common data types to wintypes.

Here's an example for defining CreateRemoteThread:

    import ctypes
    from ctypes import wintypes

    kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

    SIZE_T = ctypes.c_size_t
    LPSECURITY_ATTRIBUTES = ctypes.c_void_p
    LPTHREAD_START_ROUTINE = ctypes.WINFUNCTYPE(wintypes.DWORD, wintypes.LPVOID)

    kernel32.CreateRemoteThread.restype = wintypes.HANDLE
    kernel32.CreateRemoteThread.argtypes = (
      wintypes.HANDLE,        # hProcess
      LPSECURITY_ATTRIBUTES,  # lpThreadAttributes
      SIZE_T,                 # dwStackSize
      LPTHREAD_START_ROUTINE, # lpStartAddress
      wintypes.LPVOID,        # lpParameter
      wintypes.DWORD,         # dwCreationFlags
      wintypes.LPDWORD)       # lpThreadId

---

[1] https://docs.microsoft.com/en-us/windows/win32/api/windef/ns-windef-size
[2] https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#SIZE_T
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87336
2021-02-08 23:04:30eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg386670

resolution: not a bug
stage: resolved
2021-02-08 21:02:02nnsteincreate