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
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
40 #include "qcap_main.h"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(qcap
);
47 static LONG objects_ref
= 0;
48 static LONG server_locks
= 0;
50 static const WCHAR wAudioCaptFilter
[] =
51 {'A','u','d','i','o',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',0};
52 static const WCHAR wAVICompressor
[] =
53 {'A','V','I',' ','C','o','m','p','r','e','s','s','o','r',0};
54 static const WCHAR wVFWCaptFilter
[] =
55 {'V','F','W',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',0};
56 static const WCHAR wVFWCaptFilterProp
[] =
57 {'V','F','W',' ','C','a','p','t','u','r','e',' ','F','i','l','t','e','r',' ',
58 'P','r','o','p','e','r','t','y',' ','P','a','g','e',0};
59 static const WCHAR wAVIMux
[] =
60 {'A','V','I',' ','m','u','x',0};
61 static const WCHAR wAVIMuxPropPage
[] =
62 {'A','V','I',' ','m','u','x',' ','P','r','o','p','e','r','t','y',' ','P','a','g','e',0};
63 static const WCHAR wAVIMuxPropPage1
[] =
64 {'A','V','I',' ','m','u','x',' ','P','r','o','p','e','r','t','y',' ','P','a','g','e','1',0};
65 static const WCHAR wFileWriter
[] =
66 {'F','i','l','e',' ','W','r','i','t','e','r',0};
67 static const WCHAR wCaptGraphBuilder
[] =
68 {'C','a','p','t','u','r','e',' ','G','r','a','p','h',' ','B','u','i','l','d','e','r',0};
69 static const WCHAR wCaptGraphBuilder2
[] =
70 {'C','a','p','t','u','r','e',' ','G','r','a','p','h',' ','B','u','i','l','d','e','r','2',0};
71 static const WCHAR wInfPinTeeFilter
[] =
72 {'I','n','f','i','n','i','t','e',' ','P','i','n',' ','T','e','e',' ','F','i',
74 static const WCHAR wSmartTeeFilter
[] =
75 {'S','m','a','r','t',' ','T','e','e',' ','F','i','l','t','e','r',0};
76 static const WCHAR wAudioInMixerProp
[] =
77 {'A','u','d','i','o','I','n','p','u','t','M','i','x','e','r',' ','P','r','o',
78 'p','e','r','t','y',' ','P','a','g','e',0};
80 static CFactoryTemplate
const g_cTemplates
[] = {
84 &CLSID_AudioCaptureFilter,
85 QCAP_createAudioCaptureFilter,
90 QCAP_createAVICompressor,
95 QCAP_createVFWCaptureFilter
,
99 &CLSID_VFWCaptureFilterPropertyPage,
100 QCAP_createVFWCaptureFilterPropertyPage,
109 &CLSID_AVImuxPropertyPage,
110 QCAP_createAVImuxPropertyPage,
114 &CLSID_AVImuxPropertyPage1,
115 QCAP_createAVImuxPropertyPage1,
120 QCAP_createFileWriter,
124 &CLSID_CaptureGraphBuilder
,
125 QCAP_createCaptureGraphBuilder2
,
129 &CLSID_CaptureGraphBuilder2
,
130 QCAP_createCaptureGraphBuilder2
,
134 &CLSID_InfinitePinTeeFilter,
135 QCAP_createInfinitePinTeeFilter,
139 &CLSID_SmartTeeFilter,
140 QCAP_createSmartTeeFilter,
144 &CLSID_AudioInputMixerPropertyPage,
145 QCAP_createAudioInputMixerPropertyPage,
150 static int g_numTemplates
= sizeof(g_cTemplates
) / sizeof(g_cTemplates
[0]);
152 /***********************************************************************
153 * Dll EntryPoint (QCAP.@)
155 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
159 case DLL_PROCESS_ATTACH
:
160 DisableThreadLibraryCalls(hInstDLL
);
161 SetupInitializeServers(g_cTemplates
, g_numTemplates
, TRUE
);
163 case DLL_PROCESS_DETACH
:
164 SetupInitializeServers(g_cTemplates
, g_numTemplates
, FALSE
);
170 /***********************************************************************
171 * DllRegisterServer (QCAP.@)
173 HRESULT WINAPI
DllRegisterServer(void)
177 return SetupRegisterServers(g_cTemplates
, g_numTemplates
, TRUE
);
180 /***********************************************************************
181 * DllUnregisterServer (QCAP.@)
183 HRESULT WINAPI
DllUnregisterServer(void)
187 return SetupRegisterServers(g_cTemplates
, g_numTemplates
, FALSE
);
190 /***********************************************************************
191 * DllCanUnloadNow (QCAP.@)
193 HRESULT WINAPI
DllCanUnloadNow(void)
197 if (objects_ref
== 0 && server_locks
== 0)
202 /******************************************************************************
206 IClassFactory ITF_IClassFactory
;
209 LPFNNewCOMObject pfnCreateInstance
;
212 static HRESULT WINAPI
213 DSCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
)
215 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
217 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
218 IsEqualGUID(riid
, &IID_IClassFactory
))
220 IClassFactory_AddRef(iface
);
225 WARN("(%p)->(%s,%p), not found\n", This
, debugstr_guid(riid
), ppobj
);
226 return E_NOINTERFACE
;
229 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
231 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
232 return InterlockedIncrement(&This
->ref
);
235 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
237 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
239 ULONG ref
= InterlockedDecrement(&This
->ref
);
242 HeapFree(GetProcessHeap(), 0, This
);
247 static HRESULT WINAPI
DSCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
,
248 REFIID riid
, LPVOID
*ppobj
)
250 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
251 HRESULT hres
= ERROR_SUCCESS
;
254 TRACE("(%p)->(%p,%s,%p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
259 /* Enforce the normal OLE rules regarding interfaces and delegation */
260 if (pOuter
&& !IsEqualGUID(riid
, &IID_IUnknown
))
261 return E_NOINTERFACE
;
264 punk
= This
->pfnCreateInstance(pOuter
, &hres
);
267 /* No object created, update error if it isn't done already and return */
269 hres
= E_OUTOFMEMORY
;
275 hres
= IUnknown_QueryInterface(punk
, riid
, ppobj
);
277 /* Releasing the object. If everything was successful, QueryInterface
278 should have incremented the refcount once more, otherwise this will
280 IUnknown_Release(punk
);
284 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
286 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
287 TRACE("(%p)->(%d)\n",This
, dolock
);
290 InterlockedIncrement(&server_locks
);
292 InterlockedDecrement(&server_locks
);
296 static const IClassFactoryVtbl DSCF_Vtbl
=
305 /***********************************************************************
306 * DllGetClassObject (QCAP.@)
308 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
310 const CFactoryTemplate
*pList
= g_cTemplates
;
311 IClassFactoryImpl
*factory
;
314 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
321 if (!IsEqualGUID(&IID_IClassFactory
, riid
) &&
322 !IsEqualGUID(&IID_IUnknown
, riid
))
323 return E_NOINTERFACE
;
325 for (i
= 0; i
< g_numTemplates
; i
++, pList
++)
327 if (IsEqualGUID(pList
->m_ClsID
, rclsid
))
331 if (i
== g_numTemplates
)
333 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
334 return CLASS_E_CLASSNOTAVAILABLE
;
337 factory
= HeapAlloc(GetProcessHeap(), 0, sizeof(IClassFactoryImpl
));
339 return E_OUTOFMEMORY
;
341 factory
->ITF_IClassFactory
.lpVtbl
= &DSCF_Vtbl
;
344 factory
->pfnCreateInstance
= pList
->m_lpfnNew
;
346 *ppv
= &(factory
->ITF_IClassFactory
);
350 DWORD
ObjectRefCount(BOOL increment
)
353 return InterlockedIncrement(&objects_ref
);
354 return InterlockedDecrement(&objects_ref
);