1 | /* $Id: sw_common.c 20312 2009-06-05 10:47:35Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox D3D8/9 dll switcher
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * Sun Microsystems, Inc. confidential
|
---|
11 | * All rights reserved
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include <windows.h>
|
---|
15 | #include "switcher.h"
|
---|
16 |
|
---|
17 | static char* gsBlackList[] = {"Dwm.exe"/*, "taskeng.exe"*/, NULL};
|
---|
18 |
|
---|
19 | /* Checks if 3D is enabled for VM and it works on host machine */
|
---|
20 | BOOL isVBox3DEnabled(void)
|
---|
21 | {
|
---|
22 | DrvValidateVersionProc pDrvValidateVersion;
|
---|
23 | HANDLE hDLL;
|
---|
24 | BOOL result = FALSE;
|
---|
25 |
|
---|
26 | hDLL = LoadLibrary("VBoxOGL.dll");
|
---|
27 |
|
---|
28 | /* note: this isn't really needed as our library will refuse to load if it can't connect to host.
|
---|
29 | so it's in case we'd change it one day.
|
---|
30 | */
|
---|
31 | pDrvValidateVersion = (DrvValidateVersionProc) GetProcAddress(hDLL, "DrvValidateVersion");
|
---|
32 | if (pDrvValidateVersion)
|
---|
33 | {
|
---|
34 | result = pDrvValidateVersion(0);
|
---|
35 | }
|
---|
36 | FreeLibrary(hDLL);
|
---|
37 | return result;
|
---|
38 | }
|
---|
39 |
|
---|
40 | BOOL checkOptions(void)
|
---|
41 | {
|
---|
42 | char name[1000];
|
---|
43 | char *filename = name, *pName;
|
---|
44 | int i;
|
---|
45 |
|
---|
46 | if (!GetModuleFileName(NULL, name, 1000))
|
---|
47 | return TRUE;
|
---|
48 |
|
---|
49 | /*Extract filename*/
|
---|
50 | for (pName=name; *pName; ++pName)
|
---|
51 | {
|
---|
52 | switch (*pName)
|
---|
53 | {
|
---|
54 | case ':':
|
---|
55 | case '\\':
|
---|
56 | case '/':
|
---|
57 | filename = pName + 1;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | for (i=0; gsBlackList[i]; ++i)
|
---|
63 | {
|
---|
64 | if (!strcmp(filename, gsBlackList[i]))
|
---|
65 | return FALSE;
|
---|
66 | }
|
---|
67 |
|
---|
68 | return TRUE;
|
---|
69 | }
|
---|
70 |
|
---|
71 | void InitD3DExports(const char *vboxName, const char *msName)
|
---|
72 | {
|
---|
73 | const char *dllName;
|
---|
74 | HANDLE hDLL;
|
---|
75 |
|
---|
76 | if (isVBox3DEnabled() && checkOptions())
|
---|
77 | {
|
---|
78 | dllName = vboxName;
|
---|
79 | } else
|
---|
80 | {
|
---|
81 | dllName = msName;
|
---|
82 | }
|
---|
83 |
|
---|
84 | hDLL = LoadLibrary(dllName);
|
---|
85 | FillD3DExports(hDLL);
|
---|
86 | }
|
---|