Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendevenum_main.c
Go to the documentation of this file.
00001 /* 00002 * exported dll functions for devenum.dll 00003 * 00004 * Copyright (C) 2002 John K. Hohm 00005 * Copyright (C) 2002 Robert Shearman 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include "devenum_private.h" 00023 #include "wine/debug.h" 00024 #include "winreg.h" 00025 00026 WINE_DEFAULT_DEBUG_CHANNEL(devenum); 00027 00028 LONG dll_refs; 00029 HINSTANCE DEVENUM_hInstance; 00030 00031 typedef struct 00032 { 00033 REFCLSID clsid; 00034 LPCWSTR friendly_name; 00035 BOOL instance; 00036 } register_info; 00037 00038 static HRESULT register_clsids(int count, const register_info * pRegInfo, LPCWSTR pszThreadingModel); 00039 static void DEVENUM_RegisterQuartz(void); 00040 00041 /*********************************************************************** 00042 * Global string constant definitions 00043 */ 00044 const WCHAR clsid_keyname[6] = { 'C', 'L', 'S', 'I', 'D', 0 }; 00045 00046 /*********************************************************************** 00047 * DllEntryPoint 00048 */ 00049 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) 00050 { 00051 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad); 00052 00053 switch(fdwReason) { 00054 case DLL_PROCESS_ATTACH: 00055 DEVENUM_hInstance = hinstDLL; 00056 DisableThreadLibraryCalls(hinstDLL); 00057 break; 00058 00059 case DLL_PROCESS_DETACH: 00060 DEVENUM_hInstance = 0; 00061 break; 00062 } 00063 return TRUE; 00064 } 00065 00066 /*********************************************************************** 00067 * DllGetClassObject (DEVENUM.@) 00068 */ 00069 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv) 00070 { 00071 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv); 00072 00073 *ppv = NULL; 00074 00075 /* FIXME: we should really have two class factories. 00076 * Oh well - works just fine as it is */ 00077 if (IsEqualGUID(rclsid, &CLSID_SystemDeviceEnum) || 00078 IsEqualGUID(rclsid, &CLSID_CDeviceMoniker)) 00079 return IClassFactory_QueryInterface((IClassFactory*)&DEVENUM_ClassFactory, iid, ppv); 00080 00081 FIXME("CLSID: %s, IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid)); 00082 return CLASS_E_CLASSNOTAVAILABLE; 00083 } 00084 00085 /*********************************************************************** 00086 * DllCanUnloadNow (DEVENUM.@) 00087 */ 00088 HRESULT WINAPI DllCanUnloadNow(void) 00089 { 00090 return dll_refs != 0 ? S_FALSE : S_OK; 00091 } 00092 00093 /*********************************************************************** 00094 * DllRegisterServer (DEVENUM.@) 00095 */ 00096 HRESULT WINAPI DllRegisterServer(void) 00097 { 00098 HRESULT res; 00099 HKEY hkeyClsid = NULL; 00100 HKEY hkey1 = NULL; 00101 HKEY hkey2 = NULL; 00102 LPOLESTR pszClsidDevMon = NULL; 00103 IFilterMapper2 * pMapper = NULL; 00104 LPVOID mapvptr; 00105 static const WCHAR threadingModel[] = {'B','o','t','h',0}; 00106 static const WCHAR sysdevenum[] = {'S','y','s','t','e','m',' ','D','e','v','i','c','e',' ','E','n','u','m',0}; 00107 static const WCHAR devmon[] = {'D','e','v','i','c','e','M','o','n','i','k','e','r',0}; 00108 static const WCHAR acmcat[] = {'A','C','M',' ','C','l','a','s','s',' ','M','a','n','a','g','e','r',0}; 00109 static const WCHAR vidcat[] = {'I','C','M',' ','C','l','a','s','s',' ','M','a','n','a','g','e','r',0}; 00110 static const WCHAR filtcat[] = {'A','c','t','i','v','e','M','o','v','i','e',' ','F','i','l','t','e','r',' ','C','l','a','s','s',' ','M','a','n','a','g','e','r',0}; 00111 static const WCHAR vfwcat[] = {'V','F','W',' ','C','a','p','t','u','r','e',' ','C','l','a','s','s',' ','M','a','n','a','g','e','r',0}; 00112 static const WCHAR wavein[] = {'W','a','v','e','I','n',' ','C','l','a','s','s',' ','M','a','n','a','g','e','r', 0}; 00113 static const WCHAR waveout[] = {'W','a','v','e','O','u','t',' ','a','n','d',' ','D','S','o','u','n','d',' ','C','l','a','s','s',' ','M','a','n','a','g','e','r',0}; 00114 static const WCHAR midiout[] = {'M','i','d','i','O','u','t',' ','C','l','a','s','s',' ','M','a','n','a','g','e','r',0}; 00115 static const WCHAR amcat[] = {'A','c','t','i','v','e','M','o','v','i','e',' ','F','i','l','t','e','r',' ','C','a','t','e','g','o','r','i','e','s',0}; 00116 static const WCHAR device[] = {'d','e','v','i','c','e',0}; 00117 static const WCHAR device_1[] = {'d','e','v','i','c','e','.','1',0}; 00118 static const register_info ri[] = 00119 { 00120 {&CLSID_SystemDeviceEnum, sysdevenum, FALSE}, 00121 {&CLSID_CDeviceMoniker, devmon, FALSE}, 00122 {&CLSID_AudioCompressorCategory, acmcat, TRUE}, 00123 {&CLSID_VideoCompressorCategory, vidcat, TRUE}, 00124 {&CLSID_LegacyAmFilterCategory, filtcat, TRUE}, 00125 {&CLSID_VideoInputDeviceCategory, vfwcat, FALSE}, 00126 {&CLSID_AudioInputDeviceCategory, wavein, FALSE}, 00127 {&CLSID_AudioRendererCategory, waveout, FALSE}, 00128 {&CLSID_MidiRendererCategory, midiout, FALSE}, 00129 {&CLSID_ActiveMovieCategories, amcat, TRUE} 00130 }; 00131 00132 TRACE("\n"); 00133 00134 res = register_clsids(sizeof(ri) / sizeof(register_info), ri, threadingModel); 00135 00136 /* Quartz is needed for IFilterMapper2 */ 00137 DEVENUM_RegisterQuartz(); 00138 00139 /*** ActiveMovieFilter Categories ***/ 00140 00141 CoInitialize(NULL); 00142 00143 res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, 00144 &IID_IFilterMapper2, &mapvptr); 00145 if (SUCCEEDED(res)) 00146 { 00147 static const WCHAR friendlyvidcap[] = {'V','i','d','e','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0}; 00148 static const WCHAR friendlydshow[] = {'D','i','r','e','c','t','S','h','o','w',' ','F','i','l','t','e','r','s',0}; 00149 static const WCHAR friendlyvidcomp[] = {'V','i','d','e','o',' ','C','o','m','p','r','e','s','s','o','r','s',0}; 00150 static const WCHAR friendlyaudcap[] = {'A','u','d','i','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0}; 00151 static const WCHAR friendlyaudcomp[] = {'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','o','r','s',0}; 00152 static const WCHAR friendlyaudrend[] = {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r','s',0}; 00153 static const WCHAR friendlymidirend[] = {'M','i','d','i',' ','R','e','n','d','e','r','e','r','s',0}; 00154 static const WCHAR friendlyextrend[] = {'E','x','t','e','r','n','a','l',' ','R','e','n','d','e','r','e','r','s',0}; 00155 static const WCHAR friendlydevctrl[] = {'D','e','v','i','c','e',' ','C','o','n','t','r','o','l',' ','F','i','l','t','e','r','s',0}; 00156 00157 pMapper = mapvptr; 00158 00159 IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoInputDeviceCategory, MERIT_DO_NOT_USE, friendlyvidcap); 00160 IFilterMapper2_CreateCategory(pMapper, &CLSID_LegacyAmFilterCategory, MERIT_NORMAL, friendlydshow); 00161 IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoCompressorCategory, MERIT_DO_NOT_USE, friendlyvidcomp); 00162 IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioInputDeviceCategory, MERIT_DO_NOT_USE, friendlyaudcap); 00163 IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioCompressorCategory, MERIT_DO_NOT_USE, friendlyaudcomp); 00164 IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioRendererCategory, MERIT_NORMAL, friendlyaudrend); 00165 IFilterMapper2_CreateCategory(pMapper, &CLSID_MidiRendererCategory, MERIT_NORMAL, friendlymidirend); 00166 IFilterMapper2_CreateCategory(pMapper, &CLSID_TransmitCategory, MERIT_DO_NOT_USE, friendlyextrend); 00167 IFilterMapper2_CreateCategory(pMapper, &CLSID_DeviceControlCategory, MERIT_DO_NOT_USE, friendlydevctrl); 00168 00169 IFilterMapper2_Release(pMapper); 00170 } 00171 00172 /*** CDeviceMoniker ***/ 00173 if (SUCCEEDED(res)) 00174 { 00175 res = StringFromCLSID(&CLSID_CDeviceMoniker, &pszClsidDevMon); 00176 } 00177 if (SUCCEEDED(res)) 00178 { 00179 res = RegOpenKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkeyClsid) 00180 == ERROR_SUCCESS ? S_OK : E_FAIL; 00181 } 00182 if (SUCCEEDED(res)) 00183 { 00184 res = RegOpenKeyW(hkeyClsid, pszClsidDevMon, &hkey1) 00185 == ERROR_SUCCESS ? S_OK : E_FAIL; 00186 } 00187 if (SUCCEEDED(res)) 00188 { 00189 static const WCHAR wszProgID[] = {'P','r','o','g','I','D',0}; 00190 res = RegCreateKeyW(hkey1, wszProgID, &hkey2) 00191 == ERROR_SUCCESS ? S_OK : E_FAIL; 00192 } 00193 if (SUCCEEDED(res)) 00194 { 00195 res = RegSetValueW(hkey2, NULL, REG_SZ, device_1, (lstrlenW(device_1) + 1) * sizeof(WCHAR)) 00196 == ERROR_SUCCESS ? S_OK : E_FAIL; 00197 } 00198 00199 if (hkey2) 00200 { 00201 RegCloseKey(hkey2); 00202 hkey2 = NULL; 00203 } 00204 00205 if (SUCCEEDED(res)) 00206 { 00207 static const WCHAR wszVProgID[] = {'V','e','r','s','i','o','n','I','n','d','e','p','e','d','e','n','t','P','r','o','g','I','D',0}; 00208 res = RegCreateKeyW(hkey1, wszVProgID, &hkey2) 00209 == ERROR_SUCCESS ? S_OK : E_FAIL; 00210 } 00211 if (SUCCEEDED(res)) 00212 { 00213 res = RegSetValueW(hkey2, NULL, REG_SZ, device, (lstrlenW(device) + 1) * sizeof(WCHAR)) 00214 == ERROR_SUCCESS ? S_OK : E_FAIL; 00215 } 00216 00217 if (hkey2) 00218 { 00219 RegCloseKey(hkey2); 00220 hkey2 = NULL; 00221 } 00222 00223 if (hkey1) 00224 { 00225 RegCloseKey(hkey1); 00226 hkey1 = NULL; 00227 } 00228 00229 if (SUCCEEDED(res)) 00230 { 00231 res = RegCreateKeyW(HKEY_CLASSES_ROOT, device, &hkey1) 00232 == ERROR_SUCCESS ? S_OK : E_FAIL; 00233 } 00234 if (SUCCEEDED(res)) 00235 { 00236 res = RegCreateKeyW(hkey1, clsid_keyname, &hkey2) 00237 == ERROR_SUCCESS ? S_OK : E_FAIL; 00238 } 00239 if (SUCCEEDED(res)) 00240 { 00241 res = RegSetValueW(hkey2, NULL, REG_SZ, pszClsidDevMon, (lstrlenW(pszClsidDevMon) + 1) * sizeof(WCHAR)) 00242 == ERROR_SUCCESS ? S_OK : E_FAIL; 00243 } 00244 if (hkey2) 00245 { 00246 RegCloseKey(hkey2); 00247 hkey2 = NULL; 00248 } 00249 00250 if (hkey1) 00251 { 00252 RegCloseKey(hkey1); 00253 hkey1 = NULL; 00254 } 00255 00256 if (SUCCEEDED(res)) 00257 { 00258 res = RegCreateKeyW(HKEY_CLASSES_ROOT, device_1, &hkey1) 00259 == ERROR_SUCCESS ? S_OK : E_FAIL; 00260 } 00261 if (SUCCEEDED(res)) 00262 { 00263 res = RegCreateKeyW(hkey1, clsid_keyname, &hkey2) 00264 == ERROR_SUCCESS ? S_OK : E_FAIL; 00265 } 00266 if (SUCCEEDED(res)) 00267 { 00268 res = RegSetValueW(hkey2, NULL, REG_SZ, pszClsidDevMon, (lstrlenW(pszClsidDevMon) + 1) * sizeof(WCHAR)) 00269 == ERROR_SUCCESS ? S_OK : E_FAIL; 00270 } 00271 00272 if (hkey2) 00273 RegCloseKey(hkey2); 00274 00275 if (hkey1) 00276 RegCloseKey(hkey1); 00277 00278 if (hkeyClsid) 00279 RegCloseKey(hkeyClsid); 00280 00281 CoTaskMemFree(pszClsidDevMon); 00282 CoUninitialize(); 00283 00284 return res; 00285 } 00286 00287 /*********************************************************************** 00288 * DllUnregisterServer (DEVENUM.@) 00289 */ 00290 HRESULT WINAPI DllUnregisterServer(void) 00291 { 00292 FIXME("stub!\n"); 00293 return E_FAIL; 00294 } 00295 00296 static HRESULT register_clsids(int count, const register_info * pRegInfo, LPCWSTR pszThreadingModel) 00297 { 00298 HRESULT res = S_OK; 00299 LPOLESTR clsidString = NULL; 00300 HKEY hkeyClsid; 00301 HKEY hkeySub; 00302 HKEY hkeyInproc32; 00303 HKEY hkeyInstance = NULL; 00304 int i; 00305 static const WCHAR wcszInproc32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0}; 00306 static const WCHAR wcszThreadingModel[] = {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0}; 00307 static const WCHAR dll_module[] = {'d','e','v','e','n','u','m','.','d','l','l',0}; 00308 00309 res = RegOpenKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkeyClsid) 00310 == ERROR_SUCCESS ? S_OK : E_FAIL; 00311 00312 for (i = 0; i < count; i++) 00313 { 00314 hkeySub = 0; 00315 if (SUCCEEDED(res)) 00316 { 00317 res = StringFromCLSID(pRegInfo[i].clsid, &clsidString); 00318 } 00319 if (SUCCEEDED(res)) 00320 { 00321 res = RegCreateKeyW(hkeyClsid, clsidString, &hkeySub) 00322 == ERROR_SUCCESS ? S_OK : E_FAIL; 00323 } 00324 if (pRegInfo[i].instance && SUCCEEDED(res)) 00325 { 00326 res = RegCreateKeyW(hkeySub, wszInstanceKeyName, &hkeyInstance) 00327 == ERROR_SUCCESS ? S_OK : E_FAIL; 00328 RegCloseKey(hkeyInstance); 00329 } 00330 if (SUCCEEDED(res)) 00331 { 00332 RegSetValueW(hkeySub, 00333 NULL, 00334 REG_SZ, 00335 pRegInfo->friendly_name ? pRegInfo[i].friendly_name : clsidString, 00336 (lstrlenW(pRegInfo[i].friendly_name ? pRegInfo->friendly_name : clsidString) + 1) * sizeof(WCHAR)); 00337 res = RegCreateKeyW(hkeySub, wcszInproc32, &hkeyInproc32) 00338 == ERROR_SUCCESS ? S_OK : E_FAIL; 00339 } 00340 if (SUCCEEDED(res)) 00341 { 00342 RegSetValueW(hkeyInproc32, 00343 NULL, 00344 REG_SZ, 00345 dll_module, 00346 (lstrlenW(dll_module) + 1) * sizeof(WCHAR)); 00347 RegSetValueExW(hkeyInproc32, 00348 wcszThreadingModel, 00349 0, 00350 REG_SZ, 00351 (LPCVOID)pszThreadingModel, 00352 (lstrlenW(pszThreadingModel) + 1) * sizeof(WCHAR)); 00353 RegCloseKey(hkeyInproc32); 00354 } 00355 if (hkeySub) RegCloseKey(hkeySub); 00356 CoTaskMemFree(clsidString); 00357 clsidString = NULL; 00358 } 00359 00360 RegCloseKey(hkeyClsid); 00361 00362 return res; 00363 } 00364 00365 typedef HRESULT (WINAPI *DllRegisterServer_func)(void); 00366 00367 /* calls DllRegisterServer() for the Quartz DLL */ 00368 static void DEVENUM_RegisterQuartz(void) 00369 { 00370 HANDLE hDLL = LoadLibraryA("quartz.dll"); 00371 DllRegisterServer_func pDllRegisterServer = NULL; 00372 if (hDLL) 00373 pDllRegisterServer = (DllRegisterServer_func)GetProcAddress(hDLL, "DllRegisterServer"); 00374 if (pDllRegisterServer) 00375 { 00376 HRESULT hr = pDllRegisterServer(); 00377 if (FAILED(hr)) 00378 ERR("Failed to register Quartz. Error was 0x%x)\n", hr); 00379 } 00380 } Generated on Wed May 23 2012 04:19:20 for ReactOS by
1.7.6.1
|