1 | /* $Id: VBoxMMR.cpp 42295 2012-07-21 00:19:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxMMR - Multimedia Redirection
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012 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 |
|
---|
21 | struct VBOXMMRCONTEXT
|
---|
22 | {
|
---|
23 | HINSTANCE hMod;
|
---|
24 | HHOOK hHook;
|
---|
25 | };
|
---|
26 |
|
---|
27 | static VBOXMMRCONTEXT gCtx = {0};
|
---|
28 |
|
---|
29 | static const char *g_pszMMRDLL = "VBoxMMRHook";
|
---|
30 | static const char *g_pszMMRPROC = "CBTProc";
|
---|
31 |
|
---|
32 | void VBoxMMRCleanup(VBOXMMRCONTEXT *pCtx)
|
---|
33 | {
|
---|
34 | if (NULL != pCtx->hHook)
|
---|
35 | {
|
---|
36 | UnhookWindowsHookEx(pCtx->hHook);
|
---|
37 | }
|
---|
38 |
|
---|
39 | if (pCtx->hMod)
|
---|
40 | {
|
---|
41 | FreeLibrary(pCtx->hMod);
|
---|
42 | }
|
---|
43 |
|
---|
44 | return;
|
---|
45 | }
|
---|
46 |
|
---|
47 | int VBoxMMRInit(
|
---|
48 | const VBOXSERVICEENV *pEnv,
|
---|
49 | void **ppInstance,
|
---|
50 | bool *pfStartThread)
|
---|
51 | {
|
---|
52 | HOOKPROC pHook = NULL;
|
---|
53 |
|
---|
54 | LogRel2(("VBoxMMR: Initializing\n"));
|
---|
55 |
|
---|
56 | gCtx.hMod = LoadLibraryA(g_pszMMRDLL);
|
---|
57 | if (NULL == gCtx.hMod)
|
---|
58 | {
|
---|
59 | LogRel2(("VBoxMMR: Hooking library not found\n"));
|
---|
60 | VBoxMMRCleanup(&gCtx);
|
---|
61 | return VERR_NOT_FOUND;
|
---|
62 | }
|
---|
63 |
|
---|
64 | pHook = (HOOKPROC) GetProcAddress(gCtx.hMod, g_pszMMRPROC);
|
---|
65 | if (NULL == pHook)
|
---|
66 | {
|
---|
67 | LogRel2(("VBoxMMR: Hooking proc not found\n"));
|
---|
68 | VBoxMMRCleanup(&gCtx);
|
---|
69 | return VERR_NOT_FOUND;
|
---|
70 | }
|
---|
71 |
|
---|
72 | gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, gCtx.hMod, 0);
|
---|
73 | if (NULL == gCtx.hHook)
|
---|
74 | {
|
---|
75 | int rc = RTErrConvertFromWin32(GetLastError());
|
---|
76 | LogRel2(("VBoxMMR: Error installing hooking proc: %d\n", rc));
|
---|
77 | VBoxMMRCleanup(&gCtx);
|
---|
78 | return rc;
|
---|
79 | }
|
---|
80 |
|
---|
81 | *ppInstance = &gCtx;
|
---|
82 |
|
---|
83 | return VINF_SUCCESS;
|
---|
84 | }
|
---|
85 |
|
---|
86 | void VBoxMMRDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
|
---|
87 | {
|
---|
88 | VBOXMMRCONTEXT *pCtx = (VBOXMMRCONTEXT *) pInstance;
|
---|
89 |
|
---|
90 | VBoxMMRCleanup(pCtx);
|
---|
91 | }
|
---|
92 |
|
---|
93 | unsigned __stdcall VBoxMMRThread(void *pInstance)
|
---|
94 | {
|
---|
95 | return 0;
|
---|
96 | }
|
---|