diff --git a/comtypes/test/find_memleak.py b/comtypes/test/find_memleak.py index d27e68e1..88cf7f07 100644 --- a/comtypes/test/find_memleak.py +++ b/comtypes/test/find_memleak.py @@ -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, @@ -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 diff --git a/comtypes/test/test_ie.py b/comtypes/test/test_ie.py index dcd112f1..1e5c6095 100644 --- a/comtypes/test/test_ie.py +++ b/comtypes/test/test_ie.py @@ -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 @@ -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): diff --git a/comtypes/test/test_imfattributes.py b/comtypes/test/test_imfattributes.py index c3c2dd03..ecebdc25 100644 --- a/comtypes/test/test_imfattributes.py +++ b/comtypes/test/test_imfattributes.py @@ -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 @@ -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}")