1 | /* $Id: sw_common.c 46593 2013-06-17 14:32:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox D3D8/9 dll switcher
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2013 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 <windows.h>
|
---|
19 | #include "switcher.h"
|
---|
20 |
|
---|
21 | static char* gsBlackListExe[] = {"Dwm.exe", "java.exe", "javaw.exe", "javaws.exe"/*, "taskeng.exe"*/, NULL};
|
---|
22 | static char* gsBlackListDll[] = {"awt.dll", "wpfgfx_v0400.dll", "wpfgfx_v0300.dll", NULL};
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Loads a system DLL.
|
---|
26 | *
|
---|
27 | * @returns Module handle or NULL
|
---|
28 | * @param pszName The DLL name.
|
---|
29 | */
|
---|
30 | static HMODULE loadSystemDll(const char *pszName)
|
---|
31 | {
|
---|
32 | char szPath[MAX_PATH];
|
---|
33 | UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
|
---|
34 | size_t cbName = strlen(pszName) + 1;
|
---|
35 | if (cchPath + 1 + cbName > sizeof(szPath))
|
---|
36 | return NULL;
|
---|
37 | szPath[cchPath] = '\\';
|
---|
38 | memcpy(&szPath[cchPath + 1], pszName, cbName);
|
---|
39 | return LoadLibraryA(szPath);
|
---|
40 | }
|
---|
41 |
|
---|
42 | /* Checks if 3D is enabled for VM and it works on host machine */
|
---|
43 | BOOL isVBox3DEnabled(void)
|
---|
44 | {
|
---|
45 | DrvValidateVersionProc pDrvValidateVersion;
|
---|
46 | HANDLE hDLL;
|
---|
47 | BOOL result = FALSE;
|
---|
48 |
|
---|
49 | #ifdef VBOX_WDDM_WOW64
|
---|
50 | hDLL = loadSystemDll("VBoxOGL-x86.dll");
|
---|
51 | #else
|
---|
52 | hDLL = loadSystemDll("VBoxOGL.dll");
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | /* note: this isn't really needed as our library will refuse to load if it can't connect to host.
|
---|
56 | so it's in case we'd change it one day.
|
---|
57 | */
|
---|
58 | pDrvValidateVersion = (DrvValidateVersionProc) GetProcAddress(hDLL, "DrvValidateVersion");
|
---|
59 | if (pDrvValidateVersion)
|
---|
60 | {
|
---|
61 | result = pDrvValidateVersion(0);
|
---|
62 | }
|
---|
63 | FreeLibrary(hDLL);
|
---|
64 | return result;
|
---|
65 | }
|
---|
66 |
|
---|
67 | BOOL checkOptionsDll(void)
|
---|
68 | {
|
---|
69 | int i;
|
---|
70 | for (i=0; gsBlackListDll[i]; ++i)
|
---|
71 | {
|
---|
72 | if (GetModuleHandleA(gsBlackListDll[i]))
|
---|
73 | return FALSE;
|
---|
74 | }
|
---|
75 |
|
---|
76 | return TRUE;
|
---|
77 | }
|
---|
78 |
|
---|
79 | BOOL checkOptionsExe(void)
|
---|
80 | {
|
---|
81 | char name[1000];
|
---|
82 | char *filename = name, *pName;
|
---|
83 | int i;
|
---|
84 |
|
---|
85 | if (!GetModuleFileName(NULL, name, 1000))
|
---|
86 | return TRUE;
|
---|
87 |
|
---|
88 | /*Extract filename*/
|
---|
89 | for (pName=name; *pName; ++pName)
|
---|
90 | {
|
---|
91 | switch (*pName)
|
---|
92 | {
|
---|
93 | case ':':
|
---|
94 | case '\\':
|
---|
95 | case '/':
|
---|
96 | filename = pName + 1;
|
---|
97 | break;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | for (i=0; gsBlackListExe[i]; ++i)
|
---|
102 | {
|
---|
103 | if (!stricmp(filename, gsBlackListExe[i]))
|
---|
104 | return FALSE;
|
---|
105 | }
|
---|
106 |
|
---|
107 | return TRUE;
|
---|
108 | }
|
---|
109 |
|
---|
110 | BOOL checkOptions(void)
|
---|
111 | {
|
---|
112 | if (!checkOptionsDll())
|
---|
113 | return FALSE;
|
---|
114 |
|
---|
115 | if (!checkOptionsExe())
|
---|
116 | return FALSE;
|
---|
117 |
|
---|
118 | return TRUE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | void InitD3DExports(const char *vboxName, const char *msName)
|
---|
122 | {
|
---|
123 | const char *dllName;
|
---|
124 | HANDLE hDLL;
|
---|
125 |
|
---|
126 | if (isVBox3DEnabled() && checkOptions())
|
---|
127 | dllName = vboxName;
|
---|
128 | else
|
---|
129 | dllName = msName;
|
---|
130 |
|
---|
131 | hDLL = loadSystemDll(dllName);
|
---|
132 | FillD3DExports(hDLL);
|
---|
133 | }
|
---|
134 |
|
---|