xref: /reactos/dll/directx/bdaplgin/bdaplgin.cpp (revision 40462c92)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS BDA Proxy
4  * FILE:            dll/directx/bdaplgin/bdaplgin.cpp
5  * PURPOSE:         ClassFactory interface
6  *
7  * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 
10 #include "precomp.h"
11 
12 const GUID CBDADeviceControl_GUID = {STATIC_KSMETHODSETID_BdaChangeSync};
13 const GUID CBDAPinControl_GUID = {0x0DED49D5, 0xA8B7, 0x4d5d, {0x97, 0xA1, 0x12, 0xB0, 0xC1, 0x95, 0x87, 0x4D}};
14 
15 static INTERFACE_TABLE InterfaceTable[] =
16 {
17     {&CBDADeviceControl_GUID, CBDADeviceControl_fnConstructor},
18     {&CBDAPinControl_GUID, CBDAPinControl_fnConstructor},
19     {NULL, NULL}
20 };
21 
22 extern "C"
23 BOOL
24 WINAPI
25 DllMain(
26     HINSTANCE hInstDLL,
27     DWORD fdwReason,
28     LPVOID lpvReserved)
29 {
30     switch (fdwReason)
31     {
32         case DLL_PROCESS_ATTACH:
33             CoInitialize(NULL);
34 
35 #ifdef BDAPLGIN_TRACE
36             OutputDebugStringW(L"BDAPLGIN::DllMain()\n");
37 #endif
38 
39             DisableThreadLibraryCalls(hInstDLL);
40             break;
41     default:
42         break;
43     }
44 
45     return TRUE;
46 }
47 
48 
49 extern "C"
50 KSDDKAPI
51 HRESULT
52 WINAPI
53 DllUnregisterServer(void)
54 {
55     ULONG Index = 0;
56     LPOLESTR pStr;
57     HRESULT hr = S_OK;
58     HKEY hClass;
59 
60     if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"CLSID", 0, KEY_SET_VALUE, &hClass) != ERROR_SUCCESS)
61         return E_FAIL;
62 
63     do
64     {
65         hr = StringFromCLSID(*InterfaceTable[Index].riid, &pStr);
66         if (FAILED(hr))
67             break;
68 
69         RegDeleteKeyW(hClass, pStr);
70         CoTaskMemFree(pStr);
71         Index++;
72     }while(InterfaceTable[Index].lpfnCI != 0);
73 
74     RegCloseKey(hClass);
75     return hr;
76 }
77 
78 extern "C"
79 KSDDKAPI
80 HRESULT
81 WINAPI
82 DllRegisterServer(void)
83 {
84     ULONG Index = 0;
85     LPOLESTR pStr;
86     HRESULT hr = S_OK;
87     HKEY hClass, hKey, hSubKey;
88     static LPCWSTR ModuleName = L"bdaplgin.ax";
89     static LPCWSTR ThreadingModel = L"Both";
90 
91     if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"CLSID", 0, KEY_WRITE, &hClass) != ERROR_SUCCESS)
92         return E_FAIL;
93 
94     do
95     {
96         hr = StringFromCLSID(*InterfaceTable[Index].riid, &pStr);
97         if (FAILED(hr))
98             break;
99 
100         if (RegCreateKeyExW(hClass, pStr, 0, 0, 0, KEY_WRITE, NULL, &hKey, 0) == ERROR_SUCCESS)
101         {
102             if (RegCreateKeyExW(hKey, L"InprocServer32", 0, 0, 0, KEY_WRITE, NULL, &hSubKey, 0) == ERROR_SUCCESS)
103             {
104                 RegSetValueExW(hSubKey, 0, 0, REG_SZ, (const BYTE*)ModuleName, (wcslen(ModuleName) + 1) * sizeof(WCHAR));
105                 RegSetValueExW(hSubKey, L"ThreadingModel", 0, REG_SZ, (const BYTE*)ThreadingModel, (wcslen(ThreadingModel) + 1) * sizeof(WCHAR));
106                 RegCloseKey(hSubKey);
107             }
108             RegCloseKey(hKey);
109         }
110 
111         CoTaskMemFree(pStr);
112         Index++;
113     }while(InterfaceTable[Index].lpfnCI != 0);
114 
115     RegCloseKey(hClass);
116     return hr;
117 }
118 
119 KSDDKAPI
120 HRESULT
121 WINAPI
122 DllGetClassObject(
123     REFCLSID rclsid,
124     REFIID riid,
125     LPVOID *ppv)
126 {
127     UINT i;
128     HRESULT hres = E_OUTOFMEMORY;
129     IClassFactory * pcf = NULL;
130 
131     if (!ppv)
132         return E_INVALIDARG;
133 
134     *ppv = NULL;
135 
136     for (i = 0; InterfaceTable[i].riid; i++)
137     {
138         if (IsEqualIID(*InterfaceTable[i].riid, rclsid))
139         {
140             pcf = CClassFactory_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
141             break;
142         }
143     }
144 
145     if (!pcf)
146     {
147         return CLASS_E_CLASSNOTAVAILABLE;
148     }
149 
150     hres = pcf->QueryInterface(riid, ppv);
151     pcf->Release();
152 
153     return hres;
154 }
155 
156 KSDDKAPI
157 HRESULT
158 WINAPI
159 DllCanUnloadNow(void)
160 {
161     return S_OK;
162 }
163