advapi32: Add some tests for RegDeleteTreeA.
[wine/multimedia.git] / dlls / qcap / qcap_main.c
blob6e3cca2ea03ff3af41e9932237243bf5c8c1f79b
1 /*
2 * Qcap implementation, dllentry points
4 * Copyright (C) 2003 Dominik Strasser
5 * Copyright (C) 2005 Rolf Kalbermatter
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.
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.
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
21 #include "config.h"
23 #include <assert.h>
24 #include <stdio.h>
25 #include <stdarg.h>
27 #define COBJMACROS
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "objbase.h"
35 #include "uuids.h"
36 #include "strmif.h"
38 #include "dllsetup.h"
39 #include "qcap_main.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
46 static LONG objects_ref = 0;
47 static LONG server_locks = 0;
49 static const WCHAR wAudioCaptFilter[] =
50 {'A','u','d','i','o',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',0};
51 static const WCHAR wAVICompressor[] =
52 {'A','V','I',' ','C','o','m','p','r','e','s','s','o','r',0};
53 static const WCHAR wVFWCaptFilter[] =
54 {'V','F','W',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',0};
55 static const WCHAR wVFWCaptFilterProp[] =
56 {'V','F','W',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',' ',
57 'P','r','o','p','e','r','t','y',' ','P','a','g','e',0};
58 static const WCHAR wAVIMux[] =
59 {'A','V','I',' ','m','u','x',0};
60 static const WCHAR wAVIMuxPropPage[] =
61 {'A','V','I',' ','m','u','x',' ','P','r','o','p','e','r','t','y',' ','P','a','g','e',0};
62 static const WCHAR wAVIMuxPropPage1[] =
63 {'A','V','I',' ','m','u','x',' ','P','r','o','p','e','r','t','y',' ','P','a','g','e','1',0};
64 static const WCHAR wFileWriter[] =
65 {'F','i','l','e',' ','W','r','i','t','e','r',0};
66 static const WCHAR wCaptGraphBuilder[] =
67 {'C','a','p','t','u','r','e',' ','G','r','a','p','h',' ','B','u','i','l','d','e','r',0};
68 static const WCHAR wCaptGraphBuilder2[] =
69 {'C','a','p','t','u','r','e',' ','G','r','a','p','h',' ','B','u','i','l','d','e','r','2',0};
70 static const WCHAR wInfPinTeeFilter[] =
71 {'I','n','f','i','n','i','t','e',' ','P','i','n',' ','T','e','e',' ','F','i',
72 'l','t','e','r',0};
73 static const WCHAR wSmartTeeFilter[] =
74 {'S','m','a','r','t',' ','T','e','e',' ','F','i','l','t','e','r',0};
75 static const WCHAR wAudioInMixerProp[] =
76 {'A','u','d','i','o','I','n','p','u','t','M','i','x','e','r',' ','P','r','o',
77 'p','e','r','t','y',' ','P','a','g','e',0};
79 static CFactoryTemplate const g_cTemplates[] = {
82 wAudioCaptureFilter,
83 &CLSID_AudioCaptureFilter,
84 QCAP_createAudioCaptureFilter,
85 NULL
86 },{
87 wAVICompressor,
88 &CLSID_AVICompressor,
89 QCAP_createAVICompressor,
90 NULL
91 },*/{
92 wVFWCaptFilter,
93 &CLSID_VfwCapture,
94 QCAP_createVFWCaptureFilter,
95 NULL
96 },/*{
97 wVFWCaptFilterProp,
98 &CLSID_VFWCaptureFilterPropertyPage,
99 QCAP_createVFWCaptureFilterPropertyPage,
100 NULL
102 wAVIMux,
103 &CLSID_AVImux,
104 QCAP_createAVImux,
105 NULL
107 wAVIMuxPropPage,
108 &CLSID_AVImuxPropertyPage,
109 QCAP_createAVImuxPropertyPage,
110 NULL
112 wAVIMuxPropPage1,
113 &CLSID_AVImuxPropertyPage1,
114 QCAP_createAVImuxPropertyPage1,
115 NULL
117 wFileWriter,
118 &CLSID_FileWriter,
119 QCAP_createFileWriter,
120 NULL
121 },*/{
122 wCaptGraphBuilder,
123 &CLSID_CaptureGraphBuilder,
124 QCAP_createCaptureGraphBuilder2,
125 NULL
127 wCaptGraphBuilder2,
128 &CLSID_CaptureGraphBuilder2,
129 QCAP_createCaptureGraphBuilder2,
130 NULL
131 }/*,{
132 wInfPinTeeFilter,
133 &CLSID_InfinitePinTeeFilter,
134 QCAP_createInfinitePinTeeFilter,
135 NULL
137 wSmartTeeFilter,
138 &CLSID_SmartTeeFilter,
139 QCAP_createSmartTeeFilter,
140 NULL
142 wAudioInMixerProp,
143 &CLSID_AudioInputMixerPropertyPage,
144 QCAP_createAudioInputMixerPropertyPage,
145 NULL
149 static int g_numTemplates = sizeof(g_cTemplates) / sizeof(g_cTemplates[0]);
151 /***********************************************************************
152 * Dll EntryPoint (QCAP.@)
154 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
156 switch (fdwReason)
158 case DLL_PROCESS_ATTACH:
159 DisableThreadLibraryCalls(hInstDLL);
160 SetupInitializeServers(g_cTemplates, g_numTemplates, TRUE);
161 break;
162 case DLL_PROCESS_DETACH:
163 SetupInitializeServers(g_cTemplates, g_numTemplates, FALSE);
164 break;
166 return TRUE;
169 /***********************************************************************
170 * DllRegisterServer (QCAP.@)
172 HRESULT WINAPI DllRegisterServer(void)
174 TRACE("()\n");
176 return SetupRegisterServers(g_cTemplates, g_numTemplates, TRUE);
179 /***********************************************************************
180 * DllUnregisterServer (QCAP.@)
182 HRESULT WINAPI DllUnregisterServer(void)
184 TRACE("\n");
186 return SetupRegisterServers(g_cTemplates, g_numTemplates, FALSE);
189 /***********************************************************************
190 * DllCanUnloadNow (QCAP.@)
192 HRESULT WINAPI DllCanUnloadNow(void)
194 TRACE("\n");
196 if (objects_ref == 0 && server_locks == 0)
197 return S_OK;
198 return S_FALSE;
201 /******************************************************************************
202 * DLL ClassFactory
204 typedef struct {
205 IClassFactory ITF_IClassFactory;
207 LONG ref;
208 LPFNNewCOMObject pfnCreateInstance;
209 } IClassFactoryImpl;
211 static HRESULT WINAPI
212 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
214 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
216 if (IsEqualGUID(riid, &IID_IUnknown) ||
217 IsEqualGUID(riid, &IID_IClassFactory))
219 IClassFactory_AddRef(iface);
220 *ppobj = This;
221 return S_OK;
224 WARN("(%p)->(%s,%p), not found\n", This, debugstr_guid(riid), ppobj);
225 return E_NOINTERFACE;
228 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
230 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
231 return InterlockedIncrement(&This->ref);
234 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
236 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
238 ULONG ref = InterlockedDecrement(&This->ref);
240 if (ref == 0)
241 HeapFree(GetProcessHeap(), 0, This);
243 return ref;
246 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
247 REFIID riid, LPVOID *ppobj)
249 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
250 HRESULT hres = ERROR_SUCCESS;
251 LPUNKNOWN punk;
253 TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
255 if (!ppobj)
256 return E_POINTER;
258 /* Enforce the normal OLE rules regarding interfaces and delegation */
259 if (pOuter && !IsEqualGUID(riid, &IID_IUnknown))
260 return E_NOINTERFACE;
262 *ppobj = NULL;
263 punk = This->pfnCreateInstance(pOuter, &hres);
264 if (!punk)
266 /* No object created, update error if it isn't done already and return */
267 if (!FAILED(hres))
268 hres = E_OUTOFMEMORY;
269 return hres;
272 if (SUCCEEDED(hres))
274 hres = IUnknown_QueryInterface(punk, riid, ppobj);
276 /* Releasing the object. If everything was successful, QueryInterface
277 should have incremented the refcount once more, otherwise this will
278 purge the object. */
279 IUnknown_Release(punk);
280 return hres;
283 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
285 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
286 TRACE("(%p)->(%d)\n",This, dolock);
288 if (dolock)
289 InterlockedIncrement(&server_locks);
290 else
291 InterlockedDecrement(&server_locks);
292 return S_OK;
295 static const IClassFactoryVtbl DSCF_Vtbl =
297 DSCF_QueryInterface,
298 DSCF_AddRef,
299 DSCF_Release,
300 DSCF_CreateInstance,
301 DSCF_LockServer
304 /***********************************************************************
305 * DllGetClassObject (QCAP.@)
307 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
309 const CFactoryTemplate *pList = g_cTemplates;
310 IClassFactoryImpl *factory;
311 int i;
313 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
315 if (!ppv)
316 return E_POINTER;
318 *ppv = NULL;
320 if (!IsEqualGUID(&IID_IClassFactory, riid) &&
321 !IsEqualGUID(&IID_IUnknown, riid))
322 return E_NOINTERFACE;
324 for (i = 0; i < g_numTemplates; i++, pList++)
326 if (IsEqualGUID(pList->m_ClsID, rclsid))
327 break;
330 if (i == g_numTemplates)
332 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
333 return CLASS_E_CLASSNOTAVAILABLE;
336 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(IClassFactoryImpl));
337 if (!factory)
338 return E_OUTOFMEMORY;
340 factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
341 factory->ref = 1;
343 factory->pfnCreateInstance = pList->m_lpfnNew;
345 *ppv = &(factory->ITF_IClassFactory);
346 return S_OK;
349 DWORD ObjectRefCount(BOOL increment)
351 if (increment)
352 return InterlockedIncrement(&objects_ref);
353 return InterlockedDecrement(&objects_ref);