VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxMMR.cpp@ 51469

Last change on this file since 51469 was 51469, checked in by vboxsync, 11 years ago

VBoxTray: Logging; ripped out all custom logging.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1/* $Id: VBoxMMR.cpp 51469 2014-05-30 11:49:42Z vboxsync $ */
2/** @file
3 * VBoxMMR - Multimedia Redirection
4 */
5
6/*
7 * Copyright (C) 2012-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "VBoxTray.h"
19#include "VBoxMMR.h"
20#include <iprt/ldr.h>
21
22#ifdef DEBUG
23# define LOG_ENABLED
24# define LOG_GROUP LOG_GROUP_DEFAULT
25#endif
26#include <VBox/log.h>
27
28
29
30struct VBOXMMRCONTEXT
31{
32 RTLDRMOD hModHook;
33 HHOOK hHook;
34};
35
36static VBOXMMRCONTEXT gCtx = {0};
37
38static const char *g_pszMMRDLL = "VBoxMMRHook";
39static const char *g_pszMMRPROC = "CBTProc";
40
41void VBoxMMRCleanup(VBOXMMRCONTEXT *pCtx)
42{
43 if (pCtx->hHook)
44 {
45 UnhookWindowsHookEx(pCtx->hHook);
46 pCtx->hHook = NULL;
47 }
48
49 if (pCtx->hModHook != NIL_RTLDRMOD)
50 {
51 RTLdrClose(pCtx->hModHook);
52 pCtx->hModHook = NIL_RTLDRMOD;
53 }
54}
55
56int VBoxMMRInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
57{
58 LogFlowFuncEnter();
59
60 int rc = RTLdrLoadAppPriv(g_pszMMRDLL, &gCtx.hModHook);
61 if (RT_SUCCESS(rc))
62 {
63 HOOKPROC pHook = (HOOKPROC)RTLdrGetFunction(gCtx.hModHook, g_pszMMRPROC);
64 if (pHook)
65 {
66 HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook);
67 Assert(hMod != (HMODULE)~(uintptr_t)0);
68 gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, hMod, 0);
69 if (gCtx.hHook)
70 {
71 *ppInstance = &gCtx;
72 return VINF_SUCCESS;
73 }
74
75 rc = RTErrConvertFromWin32(GetLastError());
76 LogFlowFunc(("Error installing hooking proc: %Rrc\n", rc));
77 }
78 else
79 {
80 LogFlowFunc(("Hooking proc not found\n"));
81 rc = VERR_NOT_FOUND;
82 }
83
84 RTLdrClose(gCtx.hModHook);
85 gCtx.hModHook = NIL_RTLDRMOD;
86 }
87 else
88 LogFlowFunc(("Hooking library not found (%Rrc)\n", rc));
89
90 return rc;
91}
92
93void VBoxMMRDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
94{
95 VBOXMMRCONTEXT *pCtx = (VBOXMMRCONTEXT *) pInstance;
96
97 VBoxMMRCleanup(pCtx);
98}
99
100unsigned __stdcall VBoxMMRThread(void *pInstance)
101{
102 return 0;
103}
104
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette