Skip to content

Commit

Permalink
[GUID.py] Use WinDLL instead of oledll/windll
Browse files Browse the repository at this point in the history
Partially fix enthought#735
  • Loading branch information
moi15moi committed Jan 12, 2025
1 parent e80598b commit f309df8
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions comtypes/GUID.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""comtypes.GUID module"""

from ctypes import oledll, windll
from ctypes import HRESULT, POINTER, WinDLL
from ctypes import byref, c_wchar_p, Structure
from ctypes.wintypes import BYTE, WORD, DWORD
from ctypes.wintypes import BYTE, LPVOID, WORD, DWORD
from typing import Any, TYPE_CHECKING

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


_ole32 = oledll.ole32

_StringFromCLSID = _ole32.StringFromCLSID
_CoTaskMemFree = windll.ole32.CoTaskMemFree
_ProgIDFromCLSID = _ole32.ProgIDFromCLSID
_CLSIDFromString = _ole32.CLSIDFromString
_CLSIDFromProgID = _ole32.CLSIDFromProgID
_CoCreateGuid = _ole32.CoCreateGuid

# Note: Comparing GUID instances by comparing their buffers
# is slightly faster than using ole32.IsEqualGUID.

Expand Down Expand Up @@ -93,6 +84,36 @@ def create_new(cls) -> "hints.Self":
return guid


REFCLSID = POINTER(GUID)
LPOLESTR = LPCOLESTR = c_wchar_p
LPCLSID = POINTER(GUID)

_ole32 = WinDLL("ole32")

_StringFromCLSID = _ole32.StringFromCLSID
_StringFromCLSID.argtypes = [REFCLSID, POINTER(LPOLESTR)]
_StringFromCLSID.restype = HRESULT

_CoTaskMemFree = _ole32.CoTaskMemFree
_CoTaskMemFree.argtypes = [LPVOID]
_CoTaskMemFree.restype = None

_ProgIDFromCLSID = _ole32.ProgIDFromCLSID
_ProgIDFromCLSID.argtypes = [REFCLSID, POINTER(LPOLESTR)]
_ProgIDFromCLSID.restype = HRESULT

_CLSIDFromString = _ole32.CLSIDFromString
_CLSIDFromString.argtypes = [LPCOLESTR, LPCLSID]
_CLSIDFromString.restype = HRESULT

_CLSIDFromProgID = _ole32.CLSIDFromProgID
_CLSIDFromProgID.argtypes = [LPCOLESTR, LPCLSID]
_CLSIDFromProgID.restype = HRESULT

_CoCreateGuid = _ole32.CoCreateGuid
_CoCreateGuid.argtypes = [POINTER(GUID)]
_CoCreateGuid.restype = HRESULT

GUID_null = GUID()

__all__ = ["GUID"]

0 comments on commit f309df8

Please sign in to comment.