1 /*
2  *	exported dll functions for devenum.dll
3  *
4  * Copyright (C) 2002 John K. Hohm
5  * Copyright (C) 2002 Robert Shearman
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 #include "devenum_private.h"
23 #include "rpcproxy.h"
24 #include "wine/debug.h"
25 
26 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
27 
28 DECLSPEC_HIDDEN LONG dll_refs;
29 DECLSPEC_HIDDEN HINSTANCE DEVENUM_hInstance;
30 
31 typedef struct
32 {
33     REFCLSID clsid;
34     LPCWSTR friendly_name;
35     BOOL instance;
36 } register_info;
37 
38 #ifdef __REACTOS__
39 static void DEVENUM_RegisterQuartz(void);
40 #endif
41 
42 /***********************************************************************
43  *		Global string constant definitions
44  */
45 const WCHAR clsid_keyname[6] = { 'C', 'L', 'S', 'I', 'D', 0 };
46 
47 /***********************************************************************
48  *		DllEntryPoint
49  */
50 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
51 {
52     TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
53 
54     switch(fdwReason) {
55     case DLL_PROCESS_ATTACH:
56         DEVENUM_hInstance = hinstDLL;
57         DisableThreadLibraryCalls(hinstDLL);
58 	break;
59     }
60     return TRUE;
61 }
62 
63 /***********************************************************************
64  *		DllGetClassObject (DEVENUM.@)
65  */
66 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
67 {
68     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
69 
70     *ppv = NULL;
71 
72     /* FIXME: we should really have two class factories.
73      * Oh well - works just fine as it is */
74     if (IsEqualGUID(rclsid, &CLSID_SystemDeviceEnum) ||
75         IsEqualGUID(rclsid, &CLSID_CDeviceMoniker))
76         return IClassFactory_QueryInterface(&DEVENUM_ClassFactory.IClassFactory_iface, iid, ppv);
77 
78     FIXME("CLSID: %s, IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid));
79     return CLASS_E_CLASSNOTAVAILABLE;
80 }
81 
82 /***********************************************************************
83  *		DllCanUnloadNow (DEVENUM.@)
84  */
85 HRESULT WINAPI DllCanUnloadNow(void)
86 {
87     return dll_refs != 0 ? S_FALSE : S_OK;
88 }
89 
90 /***********************************************************************
91  *		DllRegisterServer (DEVENUM.@)
92  */
93 HRESULT WINAPI DllRegisterServer(void)
94 {
95     HRESULT res;
96     IFilterMapper2 * pMapper = NULL;
97     LPVOID mapvptr;
98 
99     TRACE("\n");
100 
101     res = __wine_register_resources( DEVENUM_hInstance );
102     if (FAILED(res))
103         return res;
104 
105 #ifdef __REACTOS__
106     /* Quartz is needed for IFilterMapper2 */
107     DEVENUM_RegisterQuartz();
108 #endif
109 
110 /*** ActiveMovieFilter Categories ***/
111 
112     CoInitialize(NULL);
113 
114     res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
115                            &IID_IFilterMapper2,  &mapvptr);
116     if (SUCCEEDED(res))
117     {
118         static const WCHAR friendlyvidcap[] = {'V','i','d','e','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0};
119         static const WCHAR friendlydshow[] = {'D','i','r','e','c','t','S','h','o','w',' ','F','i','l','t','e','r','s',0};
120         static const WCHAR friendlyvidcomp[] = {'V','i','d','e','o',' ','C','o','m','p','r','e','s','s','o','r','s',0};
121         static const WCHAR friendlyaudcap[] = {'A','u','d','i','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0};
122         static const WCHAR friendlyaudcomp[] = {'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','o','r','s',0};
123         static const WCHAR friendlyaudrend[] = {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r','s',0};
124         static const WCHAR friendlymidirend[] = {'M','i','d','i',' ','R','e','n','d','e','r','e','r','s',0};
125         static const WCHAR friendlyextrend[] = {'E','x','t','e','r','n','a','l',' ','R','e','n','d','e','r','e','r','s',0};
126         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};
127 
128         pMapper = mapvptr;
129 
130         IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoInputDeviceCategory, MERIT_DO_NOT_USE, friendlyvidcap);
131         IFilterMapper2_CreateCategory(pMapper, &CLSID_LegacyAmFilterCategory, MERIT_NORMAL, friendlydshow);
132         IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoCompressorCategory, MERIT_DO_NOT_USE, friendlyvidcomp);
133         IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioInputDeviceCategory, MERIT_DO_NOT_USE, friendlyaudcap);
134         IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioCompressorCategory, MERIT_DO_NOT_USE, friendlyaudcomp);
135         IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioRendererCategory, MERIT_NORMAL, friendlyaudrend);
136         IFilterMapper2_CreateCategory(pMapper, &CLSID_MidiRendererCategory, MERIT_NORMAL, friendlymidirend);
137         IFilterMapper2_CreateCategory(pMapper, &CLSID_TransmitCategory, MERIT_DO_NOT_USE, friendlyextrend);
138         IFilterMapper2_CreateCategory(pMapper, &CLSID_DeviceControlCategory, MERIT_DO_NOT_USE, friendlydevctrl);
139 
140         IFilterMapper2_Release(pMapper);
141     }
142 
143     CoUninitialize();
144 
145     return res;
146 }
147 
148 /***********************************************************************
149  *		DllUnregisterServer (DEVENUM.@)
150  */
151 HRESULT WINAPI DllUnregisterServer(void)
152 {
153     FIXME("stub!\n");
154     return __wine_unregister_resources( DEVENUM_hInstance );
155 }
156 
157 #ifdef __REACTOS__
158 
159 typedef HRESULT (WINAPI *DllRegisterServer_func)(void);
160 
161 /* calls DllRegisterServer() for the Quartz DLL */
162 static void DEVENUM_RegisterQuartz(void)
163 {
164     HANDLE hDLL = LoadLibraryA("quartz.dll");
165     DllRegisterServer_func pDllRegisterServer = NULL;
166     if (hDLL)
167         pDllRegisterServer = (DllRegisterServer_func)GetProcAddress(hDLL, "DllRegisterServer");
168     if (pDllRegisterServer)
169     {
170         HRESULT hr = pDllRegisterServer();
171         if (FAILED(hr))
172             ERR("Failed to register Quartz. Error was 0x%x)\n", hr);
173     }
174 }
175 
176 #endif
177