Sync with trunk revision 64099.
[reactos.git] / dll / directx / wine / devenum / devenum_main.c
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
24 #include <rpcproxy.h>
25
26 DECLSPEC_HIDDEN LONG dll_refs;
27 DECLSPEC_HIDDEN HINSTANCE DEVENUM_hInstance;
28
29 typedef struct
30 {
31 REFCLSID clsid;
32 LPCWSTR friendly_name;
33 BOOL instance;
34 } register_info;
35
36 static void DEVENUM_RegisterQuartz(void);
37
38 /***********************************************************************
39 * Global string constant definitions
40 */
41 const WCHAR clsid_keyname[6] = { 'C', 'L', 'S', 'I', 'D', 0 };
42
43 /***********************************************************************
44 * DllEntryPoint
45 */
46 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
47 {
48 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
49
50 switch(fdwReason) {
51 case DLL_PROCESS_ATTACH:
52 DEVENUM_hInstance = hinstDLL;
53 DisableThreadLibraryCalls(hinstDLL);
54 break;
55 }
56 return TRUE;
57 }
58
59 /***********************************************************************
60 * DllGetClassObject (DEVENUM.@)
61 */
62 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
63 {
64 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
65
66 *ppv = NULL;
67
68 /* FIXME: we should really have two class factories.
69 * Oh well - works just fine as it is */
70 if (IsEqualGUID(rclsid, &CLSID_SystemDeviceEnum) ||
71 IsEqualGUID(rclsid, &CLSID_CDeviceMoniker))
72 return IClassFactory_QueryInterface(&DEVENUM_ClassFactory.IClassFactory_iface, iid, ppv);
73
74 FIXME("CLSID: %s, IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid));
75 return CLASS_E_CLASSNOTAVAILABLE;
76 }
77
78 /***********************************************************************
79 * DllCanUnloadNow (DEVENUM.@)
80 */
81 HRESULT WINAPI DllCanUnloadNow(void)
82 {
83 return dll_refs != 0 ? S_FALSE : S_OK;
84 }
85
86 /***********************************************************************
87 * DllRegisterServer (DEVENUM.@)
88 */
89 HRESULT WINAPI DllRegisterServer(void)
90 {
91 HRESULT res;
92 IFilterMapper2 * pMapper = NULL;
93 LPVOID mapvptr;
94
95 TRACE("\n");
96
97 res = __wine_register_resources( DEVENUM_hInstance );
98
99 /* Quartz is needed for IFilterMapper2 */
100 DEVENUM_RegisterQuartz();
101
102 /*** ActiveMovieFilter Categories ***/
103
104 CoInitialize(NULL);
105
106 res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
107 &IID_IFilterMapper2, &mapvptr);
108 if (SUCCEEDED(res))
109 {
110 static const WCHAR friendlyvidcap[] = {'V','i','d','e','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0};
111 static const WCHAR friendlydshow[] = {'D','i','r','e','c','t','S','h','o','w',' ','F','i','l','t','e','r','s',0};
112 static const WCHAR friendlyvidcomp[] = {'V','i','d','e','o',' ','C','o','m','p','r','e','s','s','o','r','s',0};
113 static const WCHAR friendlyaudcap[] = {'A','u','d','i','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0};
114 static const WCHAR friendlyaudcomp[] = {'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','o','r','s',0};
115 static const WCHAR friendlyaudrend[] = {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r','s',0};
116 static const WCHAR friendlymidirend[] = {'M','i','d','i',' ','R','e','n','d','e','r','e','r','s',0};
117 static const WCHAR friendlyextrend[] = {'E','x','t','e','r','n','a','l',' ','R','e','n','d','e','r','e','r','s',0};
118 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};
119
120 pMapper = mapvptr;
121
122 IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoInputDeviceCategory, MERIT_DO_NOT_USE, friendlyvidcap);
123 IFilterMapper2_CreateCategory(pMapper, &CLSID_LegacyAmFilterCategory, MERIT_NORMAL, friendlydshow);
124 IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoCompressorCategory, MERIT_DO_NOT_USE, friendlyvidcomp);
125 IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioInputDeviceCategory, MERIT_DO_NOT_USE, friendlyaudcap);
126 IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioCompressorCategory, MERIT_DO_NOT_USE, friendlyaudcomp);
127 IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioRendererCategory, MERIT_NORMAL, friendlyaudrend);
128 IFilterMapper2_CreateCategory(pMapper, &CLSID_MidiRendererCategory, MERIT_NORMAL, friendlymidirend);
129 IFilterMapper2_CreateCategory(pMapper, &CLSID_TransmitCategory, MERIT_DO_NOT_USE, friendlyextrend);
130 IFilterMapper2_CreateCategory(pMapper, &CLSID_DeviceControlCategory, MERIT_DO_NOT_USE, friendlydevctrl);
131
132 IFilterMapper2_Release(pMapper);
133 }
134
135 CoUninitialize();
136
137 return res;
138 }
139
140 /***********************************************************************
141 * DllUnregisterServer (DEVENUM.@)
142 */
143 HRESULT WINAPI DllUnregisterServer(void)
144 {
145 FIXME("stub!\n");
146 return __wine_unregister_resources( DEVENUM_hInstance );
147 }
148
149 typedef HRESULT (WINAPI *DllRegisterServer_func)(void);
150
151 /* calls DllRegisterServer() for the Quartz DLL */
152 static void DEVENUM_RegisterQuartz(void)
153 {
154 HANDLE hDLL = LoadLibraryA("quartz.dll");
155 DllRegisterServer_func pDllRegisterServer = NULL;
156 if (hDLL)
157 pDllRegisterServer = (DllRegisterServer_func)GetProcAddress(hDLL, "DllRegisterServer");
158 if (pDllRegisterServer)
159 {
160 HRESULT hr = pDllRegisterServer();
161 if (FAILED(hr))
162 ERR("Failed to register Quartz. Error was 0x%x)\n", hr);
163 }
164 }