diff --git a/protocol.py b/protocol.py index eddc6391..0ce3bd76 100644 --- a/protocol.py +++ b/protocol.py @@ -125,8 +125,8 @@ elif (config.auth_force_edmc_protocol from ctypes import windll # type: ignore from ctypes import POINTER, WINFUNCTYPE, Structure, byref, c_long, c_void_p, create_unicode_buffer, wstring_at from ctypes.wintypes import ( - ATOM, BOOL, DWORD, HBRUSH, HGLOBAL, HICON, HINSTANCE, HMENU, HWND, INT, LPARAM, LPCWSTR, LPVOID, LPWSTR, MSG, - UINT, WPARAM + ATOM, BOOL, DWORD, HBRUSH, HGLOBAL, HICON, HINSTANCE, HMENU, HWND, INT, LPARAM, LPCWSTR, LPMSG, LPVOID, LPWSTR, + MSG, UINT, WPARAM ) class WNDCLASS(Structure): @@ -161,13 +161,21 @@ elif (config.auth_force_edmc_protocol # Ref: # LRESULT DefWindowProcW([in] HWND hWnd,[in] UINT Msg,[in] WPARAM wParam,[in] LPARAM lParam); # As per example at + prototype = WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM) paramflags = (1, "hWnd"), (1, "Msg"), (1, "wParam"), (1, "lParam") DefWindowProcW = prototype(("DefWindowProcW", windll.user32), paramflags) + GetParent = windll.user32.GetParent SetForegroundWindow = windll.user32.SetForegroundWindow - GetMessageW = windll.user32.GetMessageW + # + # NB: Despite 'BOOL' return type, it *can* be >0, 0 or -1, so is actually + # c_long + prototype = WINFUNCTYPE(c_long, LPMSG, HWND, UINT, UINT) + paramflags = (1, "lpMsg"), (1, "hWnd"), (1, "wMsgFilterMin"), (1, "wMsgFilterMax") + GetMessageW = prototype(("GetMessageW", windll.user32), paramflags) + TranslateMessage = windll.user32.TranslateMessage DispatchMessageW = windll.user32.DispatchMessageW PostThreadMessageW = windll.user32.PostThreadMessageW @@ -309,6 +317,17 @@ elif (config.auth_force_edmc_protocol msg = MSG() # Calls GetMessageW: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew + # Something is off with the return from this, meaning you'll see: + # Exception ignored on converting result of ctypes callback function: + # Traceback (most recent call last): + # File "C:\Users\Athan\Documents\Devel\EDMarketConnector\protocol.py", line 323, in worker + # while int(GetMessageW(byref(msg), None, 0, 0)) != 0: + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + # TypeError: 'c_long' object cannot be interpreted as an integer + # + # But it does actually work. Either getting a non-0 value and + # entering the loop, or getting 0 and exiting it. while GetMessageW(byref(msg), None, 0, 0) != 0: logger.trace_if('frontier-auth.windows', f'DDE message of type: {msg.message}') if msg.message == WM_DDE_EXECUTE: