From 5effd044accc80d99e11749d45dcb76fe1c6b4af Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 14:55:32 +0100 Subject: [PATCH] try/except ctypes.windll.user32.CalculatePopupWindowPosition As we can't rely on the is_wine check, use an exception for this. --- prefs.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/prefs.py b/prefs.py index 1ad2d71a..95612e6a 100644 --- a/prefs.py +++ b/prefs.py @@ -206,19 +206,28 @@ elif platform == 'win32': CalculatePopupWindowPosition = None if not is_wine: - CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition - CalculatePopupWindowPosition.argtypes = [ - ctypes.POINTER(POINT), - ctypes.POINTER(SIZE), - UINT, - ctypes.POINTER(RECT), - ctypes.POINTER(RECT) - ] + try: + CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition - GetParent = ctypes.windll.user32.GetParent - GetParent.argtypes = [HWND] - GetWindowRect = ctypes.windll.user32.GetWindowRect - GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] + except AttributeError as e: + logger.error( + 'win32 and not is_wine, but ctypes.windll.user32.CalculatePopupWindowPosition invalid', + exc_info=e + ) + + else: + CalculatePopupWindowPosition.argtypes = [ + ctypes.POINTER(POINT), + ctypes.POINTER(SIZE), + UINT, + ctypes.POINTER(RECT), + ctypes.POINTER(RECT) + ] + + GetParent = ctypes.windll.user32.GetParent + GetParent.argtypes = [HWND] + GetWindowRect = ctypes.windll.user32.GetWindowRect + GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] SHGetLocalizedName = ctypes.windll.shell32.SHGetLocalizedName SHGetLocalizedName.argtypes = [LPCWSTR, LPWSTR, UINT, ctypes.POINTER(ctypes.c_int)]