1 | /* $Id: sw_common.c 40650 2012-03-26 15:16:14Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox D3D8/9 dll switcher
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include <windows.h>
|
---|
20 | #include "switcher.h"
|
---|
21 |
|
---|
22 | static char* gsBlackListExe[] = {"Dwm.exe", "java.exe", "javaw.exe", "javaws.exe"/*, "taskeng.exe"*/, NULL};
|
---|
23 | static char* gsBlackListDll[] = {"awt.dll", "wpfgfx_v0400.dll", "wpfgfx_v0300.dll", NULL};
|
---|
24 |
|
---|
25 | /* Checks if 3D is enabled for VM and it works on host machine */
|
---|
26 | BOOL isVBox3DEnabled(void)
|
---|
27 | {
|
---|
28 | DrvValidateVersionProc pDrvValidateVersion;
|
---|
29 | HANDLE hDLL;
|
---|
30 | BOOL result = FALSE;
|
---|
31 |
|
---|
32 | #ifdef VBOX_WDDM_WOW64
|
---|
33 | hDLL = LoadLibrary("VBoxOGL-x86.dll");
|
---|
34 | #else
|
---|
35 | hDLL = LoadLibrary("VBoxOGL.dll");
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | /* note: this isn't really needed as our library will refuse to load if it can't connect to host.
|
---|
39 | so it's in case we'd change it one day.
|
---|
40 | */
|
---|
41 | pDrvValidateVersion = (DrvValidateVersionProc) GetProcAddress(hDLL, "DrvValidateVersion");
|
---|
42 | if (pDrvValidateVersion)
|
---|
43 | {
|
---|
44 | result = pDrvValidateVersion(0);
|
---|
45 | }
|
---|
46 | FreeLibrary(hDLL);
|
---|
47 | return result;
|
---|
48 | }
|
---|
49 |
|
---|
50 | BOOL checkOptionsDll(void)
|
---|
51 | {
|
---|
52 | int i;
|
---|
53 | for (i=0; gsBlackListDll[i]; ++i)
|
---|
54 | {
|
---|
55 | if (GetModuleHandleA(gsBlackListDll[i]))
|
---|
56 | return FALSE;
|
---|
57 | }
|
---|
58 |
|
---|
59 | return TRUE;
|
---|
60 | }
|
---|
61 |
|
---|
62 | BOOL checkOptionsExe(void)
|
---|
63 | {
|
---|
64 | char name[1000];
|
---|
65 | char *filename = name, *pName;
|
---|
66 | int i;
|
---|
67 |
|
---|
68 | if (!GetModuleFileName(NULL, name, 1000))
|
---|
69 | return TRUE;
|
---|
70 |
|
---|
71 | /*Extract filename*/
|
---|
72 | for (pName=name; *pName; ++pName)
|
---|
73 | {
|
---|
74 | switch (*pName)
|
---|
75 | {
|
---|
76 | case ':':
|
---|
77 | case '\\':
|
---|
78 | case '/':
|
---|
79 | filename = pName + 1;
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | for (i=0; gsBlackListExe[i]; ++i)
|
---|
85 | {
|
---|
86 | if (!stricmp(filename, gsBlackListExe[i]))
|
---|
87 | return FALSE;
|
---|
88 | }
|
---|
89 |
|
---|
90 | return TRUE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | BOOL checkOptions(void)
|
---|
94 | {
|
---|
95 | if (!checkOptionsDll())
|
---|
96 | return FALSE;
|
---|
97 |
|
---|
98 | if (!checkOptionsExe())
|
---|
99 | return FALSE;
|
---|
100 |
|
---|
101 | return TRUE;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void InitD3DExports(const char *vboxName, const char *msName)
|
---|
105 | {
|
---|
106 | const char *dllName;
|
---|
107 | HANDLE hDLL;
|
---|
108 |
|
---|
109 | if (isVBox3DEnabled() && checkOptions())
|
---|
110 | {
|
---|
111 | dllName = vboxName;
|
---|
112 | } else
|
---|
113 | {
|
---|
114 | dllName = msName;
|
---|
115 | }
|
---|
116 |
|
---|
117 | hDLL = LoadLibrary(dllName);
|
---|
118 | FillD3DExports(hDLL);
|
---|
119 | }
|
---|