Skip to content

Commit

Permalink
[GUID.py] Use WinDLL/OleDLL instead of windll/oledll (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
moi15moi authored Jan 25, 2025
1 parent f85ef39 commit 64345cf
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 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, OleDLL, 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,37 @@ def create_new(cls) -> "hints.Self":
return guid


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

_ole32_nohresult = WinDLL("ole32")
_ole32 = OleDLL("ole32")

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

_CoTaskMemFree = _ole32_nohresult.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 64345cf

Please sign in to comment.