Skip to content

Commit

Permalink
1.0.27?? (2024-02-08)
Browse files Browse the repository at this point in the history
---------------------
- Improvements and cleanup for win32.
  • Loading branch information
Adam Karpierz committed Feb 7, 2024
1 parent 45e37e0 commit 7a68711
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 166 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.0.27?? (2024-02-08)
---------------------
- Improvements and cleanup for win32.

1.0.27 (2024-02-05)
-------------------
- | The API has been fully updated to version 1.0.27 (libusb v.1.0.27
Expand Down
150 changes: 150 additions & 0 deletions examples/_win32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Copyright (c) 2013 Adam Karpierz
# Licensed under the zlib/libpng License
# https://opensource.org/license/zlib

import ctypes
from ctypes import windll
from ctypes import wintypes
from ctypes import WINFUNCTYPE
from ctypes.wintypes import (
CHAR, WCHAR, BOOLEAN, BOOL, BYTE, WORD, DWORD, SHORT, USHORT, INT,
UINT, LONG, ULONG, LARGE_INTEGER, ULARGE_INTEGER, FLOAT, DOUBLE,
LPBYTE, PBYTE, LPWORD, PWORD, LPDWORD, PDWORD, LPLONG, PLONG, LPSTR,
LPCSTR, LPVOID, LPCVOID, LPVOID as PVOID, HANDLE, LPHANDLE, PHANDLE,
WPARAM, LPARAM, FILETIME, LPFILETIME,
)

from ctypes.wintypes import WPARAM as ULONG_PTR # workaround
PULONG_PTR = ctypes.POINTER(ULONG_PTR)

ULONG32 = ctypes.c_uint32
ULONGLONG = ctypes.c_uint64
DWORDLONG = ctypes.c_uint64
SIZE_T = ctypes.c_size_t

WAIT_ABANDONED = 0x00000080
WAIT_OBJECT_0 = 0x00000000
WAIT_TIMEOUT = 0x00000102
WAIT_FAILED = 0xFFFFFFFF

IGNORE = 0
INFINITE = 0xFFFFFFFF

FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
FORMAT_MESSAGE_FROM_HMODULE = 0x00000800
FORMAT_MESSAGE_FROM_STRING = 0x00000400
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF

GetCurrentProcess = windll.kernel32.GetCurrentProcess
GetCurrentProcess.restype = HANDLE
GetCurrentProcess.argtypes = []

GetProcessTimes = windll.kernel32.GetProcessTimes
GetProcessTimes.restype = BOOL
GetProcessTimes.argtypes = [HANDLE,
LPFILETIME,
LPFILETIME,
LPFILETIME,
LPFILETIME]

class SECURITY_ATTRIBUTES(ctypes.Structure):
_fields_ = [
("nLength", DWORD),
("lpSecurityDescriptor", LPVOID),
("bInheritHandle", BOOL),
]
LPSECURITY_ATTRIBUTES = ctypes.POINTER(SECURITY_ATTRIBUTES)

LPTHREAD_START_ROUTINE = WINFUNCTYPE(DWORD, LPVOID)
CreateThread = windll.kernel32.CreateThread
CreateThread.restype = HANDLE
CreateThread.argtypes = [LPSECURITY_ATTRIBUTES,
SIZE_T,
LPTHREAD_START_ROUTINE,
LPVOID,
DWORD,
LPDWORD]

WaitForSingleObject = windll.kernel32.WaitForSingleObject
WaitForSingleObject.restype = DWORD
WaitForSingleObject.argtypes = [HANDLE,
DWORD]

SetEvent = windll.kernel32.SetEvent
SetEvent.restype = BOOL
SetEvent.argtypes = [HANDLE]

CreateSemaphore = windll.kernel32.CreateSemaphoreA
CreateSemaphore.restype = HANDLE
CreateSemaphore.argtypes = [LPSECURITY_ATTRIBUTES,
LONG,
LONG,
LPCSTR]

ReleaseSemaphore = windll.kernel32.ReleaseSemaphore
ReleaseSemaphore.restype = BOOL
ReleaseSemaphore.argtypes = [HANDLE,
LONG,
LPLONG]

Sleep = windll.kernel32.Sleep
Sleep.restype = None
Sleep.argtypes = [DWORD]

PHANDLER_ROUTINE = WINFUNCTYPE(BOOL, DWORD)
SetConsoleCtrlHandler = windll.kernel32.SetConsoleCtrlHandler
SetConsoleCtrlHandler.restype = BOOL
SetConsoleCtrlHandler.argtypes = [PHANDLER_ROUTINE,
BOOL]

CloseHandle = windll.kernel32.CloseHandle
CloseHandle.restype = BOOL
CloseHandle.argtypes = [HANDLE]

GetLastError = windll.kernel32.GetLastError
GetLastError.restype = DWORD
GetLastError.argtypes = []

FormatMessageA = windll.kernel32.FormatMessageA
FormatMessageA.restype = DWORD
FormatMessageA.argtypes = [DWORD,
LPCVOID,
DWORD,
DWORD,
LPSTR,
DWORD,
LPVOID]

class SYSTEMTIME(ctypes.Structure):
_fields_ = [
("wYear", WORD),
("wMonth", WORD),
("wDayOfWeek", WORD),
("wDay", WORD),
("wHour", WORD),
("wMinute", WORD),
("wSecond", WORD),
("wMilliseconds", WORD),
]
LPSYSTEMTIME = ctypes.POINTER(SYSTEMTIME)

GetLocalTime = windll.kernel32.GetLocalTime
GetLocalTime.restype = None
GetLocalTime.argtypes = [LPSYSTEMTIME]

SetLocalTime = windll.kernel32.SetLocalTime
SetLocalTime.restype = BOOL
SetLocalTime.argtypes = [LPSYSTEMTIME]

GetSystemTime = windll.kernel32.GetSystemTime
GetSystemTime.restype = None
GetSystemTime.argtypes = [LPSYSTEMTIME]

SetSystemTime = windll.kernel32.SetSystemTime
SetSystemTime.restype = BOOL
SetSystemTime.argtypes = [LPSYSTEMTIME]

del ctypes
2 changes: 1 addition & 1 deletion examples/dpfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import libusb as usb
from libusb._platform import defined, is_posix, is_windows
if is_windows: import win32
if is_windows: import _win32 as win32

usb_strerror = lambda r: usb.strerror(r).decode("utf-8")

Expand Down
81 changes: 0 additions & 81 deletions examples/win32.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/xusb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import libusb as usb
from libusb._platform import is_windows
if is_windows: import win32
if is_windows: import _win32 as win32

usb_strerror = lambda r: usb.strerror(r).decode("utf-8")
usb_error_name = lambda status: usb.error_name(status).decode("utf-8")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ requires = ['setuptools>=68.2.2', 'wheel>=0.42.0', 'packaging>=23.2.0', 'tox>=4.

[project]
name = 'libusb'
version = '1.0.27'
version = '1.0.27??'
description = 'Python binding for the libusb C library.'
urls.Homepage = 'https://pypi.org/project/libusb/'
urls.Documentation = 'https://libusb.readthedocs.io/'
Expand Down

0 comments on commit 7a68711

Please sign in to comment.