1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxSeamless - Seamless windows
|
---|
4 | *
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * If you received this file as part of a commercial VirtualBox
|
---|
19 | * distribution, then only the terms of your commercial VirtualBox
|
---|
20 | * license agreement apply instead of the previous paragraph.
|
---|
21 | *
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "VBoxService.h"
|
---|
25 | #include <VBoxHook.h>
|
---|
26 | #include <VBox/VBoxDev.h>
|
---|
27 | #include "helpers.h"
|
---|
28 |
|
---|
29 | static HMODULE hModule = 0;
|
---|
30 |
|
---|
31 | BOOL (* pfnVBoxInstallHook)(HMODULE hDll) = NULL;
|
---|
32 | BOOL (* pfnVBoxRemoveHook)() = NULL;
|
---|
33 |
|
---|
34 |
|
---|
35 | void VBoxLogString(HANDLE hDriver, char *pszStr);
|
---|
36 |
|
---|
37 | int VBoxSeamlessInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
|
---|
38 | {
|
---|
39 | *pfStartThread = false;
|
---|
40 |
|
---|
41 | /* Will fail if SetWinEventHook is not present (version < NT4 SP6 apparently) */
|
---|
42 | hModule = LoadLibrary(VBOXHOOK_DLL_NAME);
|
---|
43 | if (hModule)
|
---|
44 | {
|
---|
45 | *(uintptr_t *)&pfnVBoxInstallHook = (uintptr_t)GetProcAddress(hModule, "VBoxInstallHook");
|
---|
46 | *(uintptr_t *)&pfnVBoxRemoveHook = (uintptr_t)GetProcAddress(hModule, "VBoxRemoveHook");
|
---|
47 | }
|
---|
48 | if (pfnVBoxInstallHook)
|
---|
49 | {
|
---|
50 | /* inform the host that we support the seamless window mode */
|
---|
51 | VMMDevReqGuestCapabilities vmmreqGuestCaps = {0};
|
---|
52 | vmmdevInitRequest((VMMDevRequestHeader*)&vmmreqGuestCaps, VMMDevReq_ReportGuestCapabilities);
|
---|
53 | vmmreqGuestCaps.caps = VMMDEV_GUEST_SUPPORTS_SEAMLESS;
|
---|
54 |
|
---|
55 | DWORD cbReturned;
|
---|
56 | if (!DeviceIoControl(pEnv->hDriver, IOCTL_VBOXGUEST_VMMREQUEST, &vmmreqGuestCaps, sizeof(vmmreqGuestCaps),
|
---|
57 | &vmmreqGuestCaps, sizeof(vmmreqGuestCaps), &cbReturned, NULL))
|
---|
58 | {
|
---|
59 | SvcDebugOut2("VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError());
|
---|
60 | return VERR_INVALID_PARAMETER;
|
---|
61 | }
|
---|
62 |
|
---|
63 | pfnVBoxInstallHook(hModule);
|
---|
64 | }
|
---|
65 | return VINF_SUCCESS;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | void VBoxSeamlessDestroy (const VBOXSERVICEENV *pEnv, void *pInstance)
|
---|
70 | {
|
---|
71 | /* inform the host that we no longer support the seamless window mode */
|
---|
72 | VMMDevReqGuestCapabilities vmmreqGuestCaps = {0};
|
---|
73 | vmmdevInitRequest((VMMDevRequestHeader*)&vmmreqGuestCaps, VMMDevReq_ReportGuestCapabilities);
|
---|
74 | vmmreqGuestCaps.caps = 0;
|
---|
75 |
|
---|
76 | DWORD cbReturned;
|
---|
77 | if (!DeviceIoControl(pEnv->hDriver, IOCTL_VBOXGUEST_VMMREQUEST, &vmmreqGuestCaps, sizeof(vmmreqGuestCaps),
|
---|
78 | &vmmreqGuestCaps, sizeof(vmmreqGuestCaps), &cbReturned, NULL))
|
---|
79 | {
|
---|
80 | SvcDebugOut2("VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError());
|
---|
81 | }
|
---|
82 | if (pfnVBoxRemoveHook)
|
---|
83 | pfnVBoxRemoveHook();
|
---|
84 |
|
---|
85 | FreeLibrary(hModule);
|
---|
86 | return;
|
---|
87 | }
|
---|
88 |
|
---|
89 | #if 0
|
---|
90 |
|
---|
91 | static char LogBuffer[1024];
|
---|
92 |
|
---|
93 |
|
---|
94 | VBGLR3DECL(int) VbglR3GRPerform(HANDLE hDriver, VMMDevRequestHeader *pReq)
|
---|
95 | {
|
---|
96 | DWORD cbReturned;
|
---|
97 | if (!DeviceIoControl(hDriver, IOCTL_VBOXGUEST_VMMREQUEST, pReq, pReq->size,
|
---|
98 | pReq, pReq->size, &cbReturned, NULL))
|
---|
99 | {
|
---|
100 | SvcDebugOut2("error doing IOCTL, last error: %d\n", GetLastError());
|
---|
101 | }
|
---|
102 | return VINF_SUCCESS;
|
---|
103 | }
|
---|
104 |
|
---|
105 | void VBoxLogString(HANDLE hDriver, char *pszStr)
|
---|
106 | {
|
---|
107 | VMMDevReqLogString *pReq = (VMMDevReqLogString *)LogBuffer;
|
---|
108 | int rc;
|
---|
109 |
|
---|
110 | vmmdevInitRequest(&pReq->header, VMMDevReq_LogString);
|
---|
111 | strcpy(pReq->szString, pszStr);
|
---|
112 | pReq->header.size += strlen(pszStr);
|
---|
113 | rc = VbglR3GRPerform(hDriver, &pReq->header);
|
---|
114 | return;
|
---|
115 | }
|
---|
116 |
|
---|
117 | #endif
|
---|