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