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 | /** @todo statically link in the future; dynamic linking is just testing purposes */
|
---|
31 |
|
---|
32 | BOOL (* pfnVBoxInstallHook)(HMODULE hDll) = NULL;
|
---|
33 | BOOL (* pfnVBoxRemoveHook)() = NULL;
|
---|
34 |
|
---|
35 |
|
---|
36 | void VBoxLogString(HANDLE hDriver, char *pszStr);
|
---|
37 |
|
---|
38 | int VBoxSeamlessInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
|
---|
39 | {
|
---|
40 | *pfStartThread = false;
|
---|
41 | hModule = LoadLibrary(VBOXHOOK_DLL_NAME);
|
---|
42 | if (hModule)
|
---|
43 | {
|
---|
44 | *(uintptr_t *)&pfnVBoxInstallHook = (uintptr_t)GetProcAddress(hModule, "VBoxInstallHook");
|
---|
45 | *(uintptr_t *)&pfnVBoxRemoveHook = (uintptr_t)GetProcAddress(hModule, "VBoxRemoveHook");
|
---|
46 | }
|
---|
47 | if (pfnVBoxInstallHook)
|
---|
48 | {
|
---|
49 | /* inform the host that we support the seamless window mode */
|
---|
50 | VMMDevReqGuestCapabilities vmmreqGuestCaps = {0};
|
---|
51 | vmmdevInitRequest((VMMDevRequestHeader*)&vmmreqGuestCaps, VMMDevReq_ReportGuestCapabilities);
|
---|
52 | vmmreqGuestCaps.caps = VMMDEV_GUEST_SUPPORTS_SEAMLESS;
|
---|
53 |
|
---|
54 | DWORD cbReturned;
|
---|
55 | if (!DeviceIoControl(pEnv->hDriver, IOCTL_VBOXGUEST_VMMREQUEST, &vmmreqGuestCaps, sizeof(vmmreqGuestCaps),
|
---|
56 | &vmmreqGuestCaps, sizeof(vmmreqGuestCaps), &cbReturned, NULL))
|
---|
57 | {
|
---|
58 | SvcDebugOut2("VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError());
|
---|
59 | return VERR_INVALID_PARAMETER;
|
---|
60 | }
|
---|
61 |
|
---|
62 | pfnVBoxInstallHook(hModule);
|
---|
63 | }
|
---|
64 | return VINF_SUCCESS;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | void VBoxSeamlessDestroy (const VBOXSERVICEENV *pEnv, void *pInstance)
|
---|
69 | {
|
---|
70 | /* inform the host that we no longer support the seamless window mode */
|
---|
71 | VMMDevReqGuestCapabilities vmmreqGuestCaps = {0};
|
---|
72 | vmmdevInitRequest((VMMDevRequestHeader*)&vmmreqGuestCaps, VMMDevReq_ReportGuestCapabilities);
|
---|
73 | vmmreqGuestCaps.caps = 0;
|
---|
74 |
|
---|
75 | DWORD cbReturned;
|
---|
76 | if (!DeviceIoControl(pEnv->hDriver, IOCTL_VBOXGUEST_VMMREQUEST, &vmmreqGuestCaps, sizeof(vmmreqGuestCaps),
|
---|
77 | &vmmreqGuestCaps, sizeof(vmmreqGuestCaps), &cbReturned, NULL))
|
---|
78 | {
|
---|
79 | SvcDebugOut2("VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError());
|
---|
80 | }
|
---|
81 | if (pfnVBoxRemoveHook)
|
---|
82 | pfnVBoxRemoveHook();
|
---|
83 |
|
---|
84 | FreeLibrary(hModule);
|
---|
85 | return;
|
---|
86 | }
|
---|
87 |
|
---|
88 | #if 0
|
---|
89 |
|
---|
90 | static char LogBuffer[1024];
|
---|
91 |
|
---|
92 |
|
---|
93 | VBGLR3DECL(int) VbglR3GRPerform(HANDLE hDriver, VMMDevRequestHeader *pReq)
|
---|
94 | {
|
---|
95 | DWORD cbReturned;
|
---|
96 | if (!DeviceIoControl(hDriver, IOCTL_VBOXGUEST_VMMREQUEST, pReq, pReq->size,
|
---|
97 | pReq, pReq->size, &cbReturned, NULL))
|
---|
98 | {
|
---|
99 | SvcDebugOut2("error doing IOCTL, last error: %d\n", GetLastError());
|
---|
100 | }
|
---|
101 | return VINF_SUCCESS;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void VBoxLogString(HANDLE hDriver, char *pszStr)
|
---|
105 | {
|
---|
106 | VMMDevReqLogString *pReq = (VMMDevReqLogString *)LogBuffer;
|
---|
107 | int rc;
|
---|
108 |
|
---|
109 | vmmdevInitRequest(&pReq->header, VMMDevReq_LogString);
|
---|
110 | strcpy(pReq->szString, pszStr);
|
---|
111 | pReq->header.size += strlen(pszStr);
|
---|
112 | rc = VbglR3GRPerform(hDriver, &pReq->header);
|
---|
113 | return;
|
---|
114 | }
|
---|
115 |
|
---|
116 | #endif
|
---|