// SPDX-License-Identifier: LGPL-2.1-or-later #include "menu_bridge.h" #include "foreground_hooks.h" #include #include // Hook DLLs must match the application's architecture. This small PE host // supplies 32-bit menu/editor hooks without requiring 32-bit Linux GLib/Winelib. int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR args, int show) { (void)instance; (void)previous; (void)show; char *end; DWORD parentId = strtoul(args, &end, 10); HWND bridge = (HWND)(UINT_PTR)strtoul(end, &end, 10); DWORD bridgeProcess = 0; GetWindowThreadProcessId(bridge, &bridgeProcess); if (!parentId || bridgeProcess != parentId) return 1; HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, parentId); if (!parent) return 1; WCHAR path[4096] = {0}; DWORD length = GetModuleFileNameW(NULL, path, 4096); WCHAR *name = NULL; for (DWORD i = 0; i < length && i < 4096; ++i) if (path[i] == L'\\' || path[i] == L'/') name = path + i + 1; if (!length || length >= 4096 || !name || name - path + lstrlenW(L"wine-access-menu32.dll") >= 4096) { CloseHandle(parent); return 1; } lstrcpyW(name, L"wine-access-menu32.dll"); HMODULE module = LoadLibraryW(path); HOOKPROC callback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessMenuHook") : NULL; HOOKPROC inputCallback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessInputHook") : NULL; WineAccessForegroundHooks hooks = {module, callback, inputCallback, NULL, NULL, 0}; if (!callback || !inputCallback) fprintf(stderr, "wine-access: 32-bit menu/editor hooks unavailable (error %lu)\n", GetLastError()); if (callback && inputCallback) { while (IsWindow(bridge)) { wine_access_update_hooks(&hooks, TRUE); DWORD result = MsgWaitForMultipleObjects(1, &parent, FALSE, 100, QS_ALLINPUT); if (result == WAIT_OBJECT_0 || result == WAIT_FAILED) break; MSG message; while (PeekMessageW(&message, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&message); DispatchMessageW(&message); } } wine_access_release_hooks(&hooks); } if (module) FreeLibrary(module); CloseHandle(parent); return callback && inputCallback ? 0 : 1; }