Skip to content

Commit

Permalink
[_post_coinit\bstr.py] Use WinDLL instead of windll (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
moi15moi authored Jan 26, 2025
1 parent f05c70d commit b610843
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions comtypes/_post_coinit/bstr.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from ctypes import _SimpleCData, windll
from ctypes import _SimpleCData, WinDLL
from typing import Any, Callable, TYPE_CHECKING

if TYPE_CHECKING:
from comtypes import hints # type: ignore


_oleaut32 = WinDLL("oleaut32")

_SysFreeString = _oleaut32.SysFreeString


class BSTR(_SimpleCData):
"""The windows BSTR data type"""

Expand All @@ -18,9 +23,7 @@ def __ctypes_from_outparam__(self) -> Any:
self._needsfree = True
return self.value

def __del__(
self, _free: Callable[["BSTR"], Any] = windll.oleaut32.SysFreeString
) -> None:
def __del__(self, _free: Callable[["BSTR"], Any] = _SysFreeString) -> None:
# Free the string if self owns the memory
# or if instructed by __ctypes_from_outparam__.
if self._b_base_ is None or self._needsfree:
Expand All @@ -35,3 +38,7 @@ def from_param(cls, value: Any) -> "hints.Self":
# right thing, it doesn't ensure that SysFreeString is called
# on destruction.
return cls(value)


_SysFreeString.argtypes = [BSTR]
_SysFreeString.restype = None

0 comments on commit b610843

Please sign in to comment.