Skip to content

Commit

Permalink
Use WinDLL instead of windll (#752)
Browse files Browse the repository at this point in the history
* [test\test_imfattributes.py] Use WinDLL instead of windll

Partially fix #735

* [test\find_memleak.py] Use WinDLL instead of oledll/windll

Partially fix #735

* [test\test_ie.py] Use WinDLL instead of windll

Partially fix #735
  • Loading branch information
moi15moi authored Jan 19, 2025
1 parent 2861c9e commit a2fc2c5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
10 changes: 8 additions & 2 deletions comtypes/test/find_memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ def dump(self):
print(n, getattr(self, n) / 1e6)


_psapi = WinDLL("psapi")

_GetProcessMemoryInfo = _psapi.GetProcessMemoryInfo
_GetProcessMemoryInfo.argtypes = [HANDLE, POINTER(PROCESS_MEMORY_COUNTERS), DWORD]
_GetProcessMemoryInfo.restype = BOOL

try:
windll.psapi.GetProcessMemoryInfo.argtypes = (
_GetProcessMemoryInfo.argtypes = (
HANDLE,
POINTER(PROCESS_MEMORY_COUNTERS),
DWORD,
Expand All @@ -43,7 +49,7 @@ def find_memleak(func, loops=None):
def wss():
# Return the working set size (memory used by process)
pmi = PROCESS_MEMORY_COUNTERS()
if not windll.psapi.GetProcessMemoryInfo(-1, byref(pmi), sizeof(pmi)):
if not _GetProcessMemoryInfo(-1, byref(pmi), sizeof(pmi)):
raise WinError()
return pmi.WorkingSetSize

Expand Down
25 changes: 19 additions & 6 deletions comtypes/test/test_ie.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest as ut
from ctypes import Structure, c_long, c_uint, c_ulong
from ctypes import POINTER, Structure, WinDLL, byref, c_long, c_uint, c_ulong
from ctypes.wintypes import BOOL, HWND, LPLONG, UINT

from comtypes.client import CreateObject, GetEvents

Expand Down Expand Up @@ -58,14 +59,26 @@ class MSG(Structure):


def PumpWaitingMessages():
from ctypes import byref, windll
_user32 = WinDLL("user32")

_PeekMessageA = _user32.PeekMessageA
_PeekMessageA.argtypes = [POINTER(MSG), HWND, UINT, UINT, UINT]
_PeekMessageA.restype = BOOL

_TranslateMessage = _user32.TranslateMessage
_TranslateMessage.argtypes = [POINTER(MSG)]
_TranslateMessage.restype = BOOL

LRESULT = LPLONG
_DispatchMessageA = _user32.DispatchMessageA
_DispatchMessageA.argtypes = [POINTER(MSG)]
_DispatchMessageA.restype = LRESULT

user32 = windll.user32
msg = MSG()
PM_REMOVE = 0x0001
while user32.PeekMessageA(byref(msg), 0, 0, 0, PM_REMOVE):
user32.TranslateMessage(byref(msg))
user32.DispatchMessageA(byref(msg))
while _PeekMessageA(byref(msg), 0, 0, 0, PM_REMOVE):
_TranslateMessage(byref(msg))
_DispatchMessageA(byref(msg))


class Test(ut.TestCase):
Expand Down
14 changes: 12 additions & 2 deletions comtypes/test/test_imfattributes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
import unittest as ut

from ctypes import POINTER, pointer, windll
from ctypes import HRESULT, POINTER, WinDLL, c_uint32, pointer
from comtypes import GUID
import comtypes.client

Expand All @@ -12,8 +12,18 @@ def test_imfattributes(self):
comtypes.client.GetModule("msvidctl.dll")
from comtypes.gen import MSVidCtlLib

_mfplat = WinDLL("mfplat")

UINT32 = c_uint32
_MFCreateAttributes = _mfplat.MFCreateAttributes
_MFCreateAttributes.argtypes = [
POINTER(POINTER(MSVidCtlLib.IMFAttributes)),
UINT32,
]
_MFCreateAttributes.restype = HRESULT

imf_attrs = POINTER(MSVidCtlLib.IMFAttributes)()
hres = windll.mfplat.MFCreateAttributes(pointer(imf_attrs), 2)
hres = _MFCreateAttributes(pointer(imf_attrs), 2)
self.assertEqual(hres, 0)

MF_TRANSCODE_ADJUST_PROFILE = GUID("{9c37c21b-060f-487c-a690-80d7f50d1c72}")
Expand Down

0 comments on commit a2fc2c5

Please sign in to comment.