Skip to content

Commit

Permalink
Replace alias definitions with ctypes.wintypes
Browse files Browse the repository at this point in the history
imports
  • Loading branch information
fmtabler committed Dec 8, 2024
1 parent df2c5ac commit d16ef33
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 15 deletions.
8 changes: 2 additions & 6 deletions comtypes/GUID.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""comtypes.GUID module"""

from ctypes import oledll, windll
from ctypes import byref, c_byte, c_ushort, c_ulong, c_wchar_p, Structure
from ctypes import byref, c_wchar_p, Structure
from ctypes.wintypes import BYTE, WORD, DWORD
from typing import Any, TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -11,11 +12,6 @@
def binary(obj: "GUID") -> bytes:
return bytes(obj)


BYTE = c_byte
WORD = c_ushort
DWORD = c_ulong

_ole32 = oledll.ole32

_StringFromCLSID = _ole32.StringFromCLSID
Expand Down
2 changes: 1 addition & 1 deletion comtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ctypes import HRESULT # noqa
from ctypes import _Pointer, _SimpleCData # noqa
from ctypes import c_int, c_ulong, oledll, windll
from ctypes.wintypes import DWORD
import logging
import sys
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -72,7 +73,6 @@ class ReturnHRESULT(Exception):

_GUID = GUID
IID = GUID
DWORD = c_ulong

wireHWND = c_ulong

Expand Down
3 changes: 1 addition & 2 deletions comtypes/_safearray.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""SAFEARRAY api functions, data types, and constants."""

from ctypes import c_uint, c_ushort, c_void_p, POINTER, Structure, WinDLL
from ctypes.wintypes import DWORD, LONG, UINT
from ctypes.wintypes import DWORD, LONG, UINT, USHORT

from comtypes import HRESULT, GUID

Expand All @@ -19,7 +19,6 @@

VARTYPE = c_ushort
PVOID = c_void_p
USHORT = c_ushort

_oleaut32 = WinDLL("oleaut32")

Expand Down
2 changes: 1 addition & 1 deletion comtypes/errorinfo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys
from ctypes import *
from ctypes.wintypes import DWORD
from comtypes import IUnknown, HRESULT, COMMETHOD, GUID, BSTR
from comtypes.hresult import *

LPCOLESTR = c_wchar_p
DWORD = c_ulong


class ICreateErrorInfo(IUnknown):
Expand Down
2 changes: 1 addition & 1 deletion comtypes/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from ctypes import *
from ctypes.wintypes import DWORD
from comtypes import (
IUnknown,
STDMETHOD,
Expand All @@ -15,7 +16,6 @@
CLSCTX_INPROC_SERVER,
)

DWORD = c_ulong


class IGlobalInterfaceTable(IUnknown):
Expand Down
5 changes: 1 addition & 4 deletions comtypes/typeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import ctypes
from ctypes import HRESULT, POINTER, _Pointer, byref, c_int, c_void_p, c_wchar_p
from ctypes.wintypes import DWORD, LONG, UINT, ULONG, WCHAR, WORD
from ctypes.wintypes import DWORD, LONG, UINT, ULONG, WCHAR, WORD, INT, SHORT, USHORT
from comtypes import BSTR, _CData, COMMETHOD, GUID, IID, IUnknown, STDMETHOD
from comtypes.automation import DISPID, LCID, SCODE
from comtypes.automation import DISPPARAMS, EXCEPINFO, VARIANT, VARIANTARG, VARTYPE
Expand All @@ -28,15 +28,12 @@

BOOL = c_int
HREFTYPE = DWORD
INT = c_int
MEMBERID = DISPID
OLECHAR = WCHAR
PVOID = c_void_p
SHORT = ctypes.c_short
# See https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#ULONG_PTR # noqa
ULONG_PTR = ctypes.c_uint64 if is_64_bit else ctypes.c_ulong

USHORT = ctypes.c_ushort
LPOLESTR = POINTER(OLECHAR)

################################################################
Expand Down

0 comments on commit d16ef33

Please sign in to comment.