int VBoxSeamlessInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread) { Log(("VBoxTray: VBoxSeamlessInit\n")); *pfStartThread = false; gCtx.pEnv = pEnv; gCtx.hModHook = NIL_RTLDRMOD; OSVERSIONINFO OSinfo; OSinfo.dwOSVersionInfoSize = sizeof (OSinfo); GetVersionEx (&OSinfo); int rc = VINF_SUCCESS; /* We have to jump out here when using NT4, otherwise it complains about a missing API function "UnhookWinEvent" used by the dynamically loaded VBoxHook.dll below */ if (OSinfo.dwMajorVersion <= 4) /* Windows NT 4.0 or older */ { Log(("VBoxTray: VBoxSeamlessInit: Windows NT 4.0 or older not supported!\n")); rc = VERR_NOT_SUPPORTED; } else { /* Will fail if SetWinEventHook is not present (version < NT4 SP6 apparently) */ rc = RTLdrLoadAppPriv(VBOXHOOK_DLL_NAME, &gCtx.hModHook); if (RT_SUCCESS(rc)) { *(PFNRT *)&gCtx.pfnVBoxHookInstallWindowTracker = RTLdrGetFunction(gCtx.hModHook, "VBoxHookInstallWindowTracker"); *(PFNRT *)&gCtx.pfnVBoxHookRemoveWindowTracker = RTLdrGetFunction(gCtx.hModHook, "VBoxHookRemoveWindowTracker"); /* rc should contain success status */ AssertRC(rc); VBoxSeamlessSetSupported(TRUE); // if (RT_SUCCESS(rc)) { *pfStartThread = true; *ppInstance = &gCtx; } } else Log(("VBoxTray: VBoxSeamlessInit: LoadLibrary of \"%s\" failed with rc=%Rrc\n", VBOXHOOK_DLL_NAME, rc)); } return rc; }
DECLCALLBACK(int) VBoxSeamlessInit(const PVBOXSERVICEENV pEnv, void **ppInstance) { LogFlowFuncEnter(); PVBOXSEAMLESSCONTEXT pCtx = &g_Ctx; /* Only one instance at the moment. */ AssertPtr(pCtx); pCtx->pEnv = pEnv; pCtx->hModHook = NIL_RTLDRMOD; OSVERSIONINFO OSinfo; OSinfo.dwOSVersionInfoSize = sizeof (OSinfo); GetVersionEx (&OSinfo); int rc; /* We have to jump out here when using NT4, otherwise it complains about a missing API function "UnhookWinEvent" used by the dynamically loaded VBoxHook.dll below */ if (OSinfo.dwMajorVersion <= 4) /* Windows NT 4.0 or older */ { Log(("VBoxTray: VBoxSeamlessInit: Windows NT 4.0 or older not supported!\n")); rc = VERR_NOT_SUPPORTED; } else { /* Will fail if SetWinEventHook is not present (version < NT4 SP6 apparently) */ rc = RTLdrLoadAppPriv(VBOXHOOK_DLL_NAME, &pCtx->hModHook); if (RT_SUCCESS(rc)) { *(PFNRT *)&pCtx->pfnVBoxHookInstallWindowTracker = RTLdrGetFunction(pCtx->hModHook, "VBoxHookInstallWindowTracker"); *(PFNRT *)&pCtx->pfnVBoxHookRemoveWindowTracker = RTLdrGetFunction(pCtx->hModHook, "VBoxHookRemoveWindowTracker"); /* rc should contain success status */ AssertRC(rc); /** @todo r=andy Makes no sense here!? */ VBoxSeamlessSetSupported(TRUE); *ppInstance = pCtx; } else LogFlowFunc(("Unable to load %s, rc=%Rrc\n", VBOXHOOK_DLL_NAME, rc)); } LogFlowFuncLeaveRC(rc); return rc; }
int VBoxMMRInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread) { LogFlowFuncEnter(); int rc = RTLdrLoadAppPriv(g_pszMMRDLL, &gCtx.hModHook); if (RT_SUCCESS(rc)) { HOOKPROC pHook = (HOOKPROC)RTLdrGetFunction(gCtx.hModHook, g_pszMMRPROC); if (pHook) { HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook); Assert(hMod != (HMODULE)~(uintptr_t)0); gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, hMod, 0); if (gCtx.hHook) { *ppInstance = &gCtx; return VINF_SUCCESS; } rc = RTErrConvertFromWin32(GetLastError()); LogFlowFunc(("Error installing hooking proc: %Rrc\n", rc)); } else { LogFlowFunc(("Hooking proc not found\n")); rc = VERR_NOT_FOUND; } RTLdrClose(gCtx.hModHook); gCtx.hModHook = NIL_RTLDRMOD; } else LogFlowFunc(("Hooking library not found (%Rrc)\n", rc)); return rc; }