1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2011 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | |
---|
5 | #pragma once |
---|
6 | |
---|
7 | #include "rodshow.h" |
---|
8 | #include "DirectShowSpy_i.h" |
---|
9 | #include "Common.h" |
---|
10 | |
---|
11 | //////////////////////////////////////////////////////////// |
---|
12 | // CSystemDeviceEnumeratorSpyT |
---|
13 | |
---|
14 | // NOTE: Original CLSID_SystemDeviceEnum does not support aggregation |
---|
15 | |
---|
16 | template <typename T, const CLSID* t_pSystemDeviceEnumeratorClassIdentifier> |
---|
17 | class ATL_NO_VTABLE CSystemDeviceEnumeratorSpyT : |
---|
18 | public CComObjectRootEx<CComMultiThreadModel>, |
---|
19 | //public CComCoClass<CSystemDeviceEnumeratorSpyT, &CLSID_SystemDeviceEnumeratorSpy>, |
---|
20 | public CTransparentCoClassT<T, t_pSystemDeviceEnumeratorClassIdentifier>, |
---|
21 | public IDispatchImpl<ISystemDeviceEnumeratorSpy>, |
---|
22 | public ICreateDevEnum |
---|
23 | { |
---|
24 | typedef CSystemDeviceEnumeratorSpyT<T, t_pSystemDeviceEnumeratorClassIdentifier> CSystemDeviceEnumeratorSpy; |
---|
25 | |
---|
26 | public: |
---|
27 | //enum { IDR = IDR_SYSTEMDEVICEENUMERATORSPY }; |
---|
28 | |
---|
29 | //DECLARE_REGISTRY_RESOURCEID(IDR) |
---|
30 | |
---|
31 | DECLARE_PROTECT_FINAL_CONSTRUCT() |
---|
32 | |
---|
33 | DECLARE_GET_CONTROLLING_UNKNOWN() |
---|
34 | |
---|
35 | DECLARE_QI_TRACE(CSystemDeviceEnumeratorSpy) |
---|
36 | |
---|
37 | BEGIN_COM_MAP(CSystemDeviceEnumeratorSpy) |
---|
38 | COM_INTERFACE_ENTRY(ISystemDeviceEnumeratorSpy) |
---|
39 | COM_INTERFACE_ENTRY(ICreateDevEnum) |
---|
40 | COM_INTERFACE_ENTRY_FUNC(CLSID_SystemDeviceEnum, 0, QuerySystemDeviceEnumInterface) |
---|
41 | //COM_INTERFACE_ENTRY(IDispatch) |
---|
42 | END_COM_MAP() |
---|
43 | |
---|
44 | public: |
---|
45 | |
---|
46 | //////////////////////////////////////////////////////// |
---|
47 | // CPropertyBag |
---|
48 | |
---|
49 | class ATL_NO_VTABLE CPropertyBag : |
---|
50 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
51 | public IPropertyBag, |
---|
52 | public IPropertyBag2 |
---|
53 | { |
---|
54 | public: |
---|
55 | |
---|
56 | DECLARE_QI_TRACE(CPropertyBag) |
---|
57 | |
---|
58 | BEGIN_COM_MAP(CPropertyBag) |
---|
59 | COM_INTERFACE_ENTRY(IPropertyBag2) |
---|
60 | COM_INTERFACE_ENTRY(IPropertyBag) |
---|
61 | END_COM_MAP() |
---|
62 | |
---|
63 | private: |
---|
64 | CComPtr<IPropertyBag> m_pPropertyBag; |
---|
65 | CComPtr<IPropertyBag2> m_pPropertyBag2; |
---|
66 | |
---|
67 | public: |
---|
68 | // CPropertyBag |
---|
69 | CPropertyBag() |
---|
70 | { |
---|
71 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
72 | } |
---|
73 | ~CPropertyBag() |
---|
74 | { |
---|
75 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
76 | } |
---|
77 | VOID Initialize(IPropertyBag* pPropertyBag) |
---|
78 | { |
---|
79 | _A(pPropertyBag); |
---|
80 | _A(!m_pPropertyBag); |
---|
81 | m_pPropertyBag = pPropertyBag; |
---|
82 | m_pPropertyBag2 = CComQIPtr<IPropertyBag2>(pPropertyBag); |
---|
83 | } |
---|
84 | |
---|
85 | // IPropertyBag |
---|
86 | STDMETHOD(Read)(LPCOLESTR pszPropertyName, VARIANT* pvValue, IErrorLog* pErrorLog) throw() |
---|
87 | { |
---|
88 | _Z4(atlTraceCOM, 4, _T("pszPropertyName %s\n"), CString(pszPropertyName)); |
---|
89 | _ATLTRY |
---|
90 | { |
---|
91 | HRESULT nResult = m_pPropertyBag->Read(pszPropertyName, pvValue, pErrorLog); |
---|
92 | #pragma region DevicePath Fix for Skype 6.0.0.126 |
---|
93 | //if(nResult == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) && pszPropertyName && _wcsicmp(pszPropertyName, L"DevicePath") == 0 && pvValue) |
---|
94 | //{ |
---|
95 | // _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
96 | // CComVariant vValue = L"\\\\?\\fake"; |
---|
97 | // _V(vValue.Detach(pvValue)); |
---|
98 | // nResult = S_OK; |
---|
99 | //} |
---|
100 | #pragma endregion |
---|
101 | if(SUCCEEDED(nResult)) |
---|
102 | { |
---|
103 | CString sValue = _T("???"); |
---|
104 | CComVariant vStringValue; |
---|
105 | if(SUCCEEDED(vStringValue.ChangeType(VT_BSTR, pvValue))) |
---|
106 | sValue = CString(vStringValue.bstrVal); |
---|
107 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x, pvValue->vt 0x%x, %s\n"), nResult, pvValue->vt, sValue); |
---|
108 | } else |
---|
109 | { |
---|
110 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
111 | } |
---|
112 | return nResult; |
---|
113 | } |
---|
114 | _ATLCATCH(Exception) |
---|
115 | { |
---|
116 | _C(Exception); |
---|
117 | } |
---|
118 | return S_OK; |
---|
119 | } |
---|
120 | STDMETHOD(Write)(LPCOLESTR pszPropertyName, VARIANT* pvValue) throw() |
---|
121 | { |
---|
122 | _Z4(atlTraceCOM, 4, _T("pszPropertyName %s, pvValue->vt 0x%x\n"), CString(pszPropertyName), pvValue->vt); |
---|
123 | _ATLTRY |
---|
124 | { |
---|
125 | const HRESULT nResult = m_pPropertyBag->Write(pszPropertyName, pvValue); |
---|
126 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
127 | return nResult; |
---|
128 | } |
---|
129 | _ATLCATCH(Exception) |
---|
130 | { |
---|
131 | _C(Exception); |
---|
132 | } |
---|
133 | return S_OK; |
---|
134 | } |
---|
135 | |
---|
136 | // IPropertyBag2 |
---|
137 | STDMETHOD(Read)(ULONG cProperties, PROPBAG2 *pPropBag, IErrorLog *pErrLog, VARIANT *pvarValue, HRESULT *phrError) throw() |
---|
138 | { |
---|
139 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
140 | _ATLTRY |
---|
141 | { |
---|
142 | const HRESULT nResult = m_pPropertyBag2->Read(cProperties, pPropBag, pErrLog, pvarValue, phrError); |
---|
143 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
144 | return nResult; |
---|
145 | } |
---|
146 | _ATLCATCH(Exception) |
---|
147 | { |
---|
148 | _C(Exception); |
---|
149 | } |
---|
150 | return S_OK; |
---|
151 | } |
---|
152 | STDMETHOD(Write)(ULONG cProperties, PROPBAG2 *pPropBag, VARIANT *pvarValue) throw() |
---|
153 | { |
---|
154 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
155 | _ATLTRY |
---|
156 | { |
---|
157 | const HRESULT nResult = m_pPropertyBag2->Write(cProperties, pPropBag, pvarValue); |
---|
158 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
159 | return nResult; |
---|
160 | } |
---|
161 | _ATLCATCH(Exception) |
---|
162 | { |
---|
163 | _C(Exception); |
---|
164 | } |
---|
165 | return S_OK; |
---|
166 | } |
---|
167 | STDMETHOD(CountProperties)(ULONG *pcProperties) throw() |
---|
168 | { |
---|
169 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
170 | _ATLTRY |
---|
171 | { |
---|
172 | const HRESULT nResult = m_pPropertyBag2->CountProperties(pcProperties); |
---|
173 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
174 | return nResult; |
---|
175 | } |
---|
176 | _ATLCATCH(Exception) |
---|
177 | { |
---|
178 | _C(Exception); |
---|
179 | } |
---|
180 | return S_OK; |
---|
181 | } |
---|
182 | STDMETHOD(GetPropertyInfo)(ULONG iProperty, ULONG cProperties, PROPBAG2* pPropBag, ULONG *pcProperties) throw() |
---|
183 | { |
---|
184 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
185 | _ATLTRY |
---|
186 | { |
---|
187 | const HRESULT nResult = m_pPropertyBag2->GetPropertyInfo(iProperty, cProperties, pPropBag, pcProperties); |
---|
188 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
189 | return nResult; |
---|
190 | } |
---|
191 | _ATLCATCH(Exception) |
---|
192 | { |
---|
193 | _C(Exception); |
---|
194 | } |
---|
195 | return S_OK; |
---|
196 | } |
---|
197 | STDMETHOD(LoadObject)(LPCOLESTR pstrName, DWORD dwHint, IUnknown *pUnkObject, IErrorLog *pErrLog) throw() |
---|
198 | { |
---|
199 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
200 | _ATLTRY |
---|
201 | { |
---|
202 | const HRESULT nResult = m_pPropertyBag2->LoadObject(pstrName, dwHint, pUnkObject, pErrLog); |
---|
203 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
204 | return nResult; |
---|
205 | } |
---|
206 | _ATLCATCH(Exception) |
---|
207 | { |
---|
208 | _C(Exception); |
---|
209 | } |
---|
210 | return S_OK; |
---|
211 | } |
---|
212 | }; |
---|
213 | |
---|
214 | //////////////////////////////////////////////////////// |
---|
215 | // CMoniker |
---|
216 | |
---|
217 | class ATL_NO_VTABLE CMoniker : |
---|
218 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
219 | public IMoniker |
---|
220 | { |
---|
221 | public: |
---|
222 | |
---|
223 | DECLARE_QI_TRACE(CMoniker) |
---|
224 | |
---|
225 | BEGIN_COM_MAP(CMoniker) |
---|
226 | COM_INTERFACE_ENTRY(IMoniker) |
---|
227 | COM_INTERFACE_ENTRY(IPersistStream) |
---|
228 | COM_INTERFACE_ENTRY(IPersist) |
---|
229 | END_COM_MAP() |
---|
230 | |
---|
231 | private: |
---|
232 | CComPtr<IMoniker> m_pMoniker; |
---|
233 | |
---|
234 | public: |
---|
235 | // CMoniker |
---|
236 | CMoniker() |
---|
237 | { |
---|
238 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
239 | } |
---|
240 | ~CMoniker() |
---|
241 | { |
---|
242 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
243 | } |
---|
244 | VOID Initialize(IMoniker* pMoniker) |
---|
245 | { |
---|
246 | _A(pMoniker); |
---|
247 | _A(!m_pMoniker); |
---|
248 | m_pMoniker = pMoniker; |
---|
249 | } |
---|
250 | |
---|
251 | // IPersist |
---|
252 | STDMETHOD(GetClassID)(CLSID* pClassIdentifier) throw() |
---|
253 | { |
---|
254 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
255 | return m_pMoniker->GetClassID(pClassIdentifier); |
---|
256 | } |
---|
257 | |
---|
258 | // IPersistStream |
---|
259 | STDMETHOD(IsDirty)() throw() |
---|
260 | { |
---|
261 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
262 | return m_pMoniker->IsDirty(); |
---|
263 | } |
---|
264 | STDMETHOD(Load)(IStream* pStream) throw() |
---|
265 | { |
---|
266 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
267 | return m_pMoniker->Load(pStream); |
---|
268 | } |
---|
269 | STDMETHOD(Save)(IStream* pStream, BOOL bClearDirty) throw() |
---|
270 | { |
---|
271 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
272 | return m_pMoniker->Save(pStream, bClearDirty); |
---|
273 | } |
---|
274 | STDMETHOD(GetSizeMax)(ULARGE_INTEGER* pnMaximalSize) throw() |
---|
275 | { |
---|
276 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
277 | return m_pMoniker->GetSizeMax(pnMaximalSize); |
---|
278 | } |
---|
279 | |
---|
280 | // IMoniker |
---|
281 | STDMETHOD(BindToObject)(IBindCtx* pBindCtx, IMoniker* pLeftMoniker, REFIID InterfaceIdentifier, VOID** ppvObject) throw() |
---|
282 | { |
---|
283 | _Z4(atlTraceCOM, 4, _T("pBindCtx 0x%p, pLeftMoniker 0x%p, InterfaceIdentifier %ls\n"), pBindCtx, pLeftMoniker, _PersistHelper::StringFromInterfaceIdentifier(InterfaceIdentifier)); |
---|
284 | _ATLTRY |
---|
285 | { |
---|
286 | return m_pMoniker->BindToObject(pBindCtx, pLeftMoniker, InterfaceIdentifier, ppvObject); |
---|
287 | } |
---|
288 | _ATLCATCH(Exception) |
---|
289 | { |
---|
290 | _C(Exception); |
---|
291 | } |
---|
292 | return S_OK; |
---|
293 | } |
---|
294 | STDMETHOD(BindToStorage)(IBindCtx* pBindCtx, IMoniker* pLeftMoniker, REFIID InterfaceIdentifier, VOID** ppvObject) throw() |
---|
295 | { |
---|
296 | _Z4(atlTraceCOM, 4, _T("pBindCtx 0x%p, pLeftMoniker 0x%p, InterfaceIdentifier %ls\n"), pBindCtx, pLeftMoniker, _PersistHelper::StringFromInterfaceIdentifier(InterfaceIdentifier)); |
---|
297 | _ATLTRY |
---|
298 | { |
---|
299 | const HRESULT nResult = m_pMoniker->BindToStorage(pBindCtx, pLeftMoniker, InterfaceIdentifier, ppvObject); |
---|
300 | if(SUCCEEDED(nResult) && *ppvObject) |
---|
301 | { |
---|
302 | if(InterfaceIdentifier == __uuidof(IPropertyBag) || InterfaceIdentifier == __uuidof(IPropertyBag2)) |
---|
303 | { |
---|
304 | CComPtr<IPropertyBag>& pPropertyBag = reinterpret_cast<CComPtr<IPropertyBag>&>(*ppvObject); |
---|
305 | CObjectPtr<CPropertyBag> pPropertyBagWrapper; |
---|
306 | pPropertyBagWrapper.Construct()->Initialize(pPropertyBag); |
---|
307 | pPropertyBag = pPropertyBagWrapper; |
---|
308 | } |
---|
309 | } |
---|
310 | return nResult; |
---|
311 | } |
---|
312 | _ATLCATCH(Exception) |
---|
313 | { |
---|
314 | _C(Exception); |
---|
315 | } |
---|
316 | return S_OK; |
---|
317 | } |
---|
318 | STDMETHOD(Reduce)(IBindCtx* pBindCtx, DWORD nDepth, IMoniker** ppLeftMoniker, IMoniker** ppReducedMoniker) throw() |
---|
319 | { |
---|
320 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
321 | _ATLTRY |
---|
322 | { |
---|
323 | return m_pMoniker->Reduce(pBindCtx, nDepth, ppLeftMoniker, ppReducedMoniker); |
---|
324 | } |
---|
325 | _ATLCATCH(Exception) |
---|
326 | { |
---|
327 | _C(Exception); |
---|
328 | } |
---|
329 | return S_OK; |
---|
330 | } |
---|
331 | STDMETHOD(ComposeWith)(IMoniker* pRightMoniker, BOOL bOnlyIfNotGeneric, IMoniker** ppCompositeMoniker) throw() |
---|
332 | { |
---|
333 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
334 | _ATLTRY |
---|
335 | { |
---|
336 | return m_pMoniker->ComposeWith(pRightMoniker, bOnlyIfNotGeneric, ppCompositeMoniker); |
---|
337 | } |
---|
338 | _ATLCATCH(Exception) |
---|
339 | { |
---|
340 | _C(Exception); |
---|
341 | } |
---|
342 | return S_OK; |
---|
343 | } |
---|
344 | STDMETHOD(Enum)(BOOL bForward, IEnumMoniker** ppEnumMoniker) throw() |
---|
345 | { |
---|
346 | _Z4(atlTraceCOM, 4, _T("bForward %d\n"), bForward); |
---|
347 | _ATLTRY |
---|
348 | { |
---|
349 | return m_pMoniker->Enum(bForward, ppEnumMoniker); |
---|
350 | } |
---|
351 | _ATLCATCH(Exception) |
---|
352 | { |
---|
353 | _C(Exception); |
---|
354 | } |
---|
355 | return S_OK; |
---|
356 | } |
---|
357 | STDMETHOD(IsEqual)(IMoniker* pMoniker) throw() |
---|
358 | { |
---|
359 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
360 | _ATLTRY |
---|
361 | { |
---|
362 | return m_pMoniker->IsEqual(pMoniker); |
---|
363 | } |
---|
364 | _ATLCATCH(Exception) |
---|
365 | { |
---|
366 | _C(Exception); |
---|
367 | } |
---|
368 | return S_OK; |
---|
369 | } |
---|
370 | STDMETHOD(Hash)(DWORD* pnHashValue) throw() |
---|
371 | { |
---|
372 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
373 | _ATLTRY |
---|
374 | { |
---|
375 | return m_pMoniker->Hash(pnHashValue); |
---|
376 | } |
---|
377 | _ATLCATCH(Exception) |
---|
378 | { |
---|
379 | _C(Exception); |
---|
380 | } |
---|
381 | return S_OK; |
---|
382 | } |
---|
383 | STDMETHOD(IsRunning)(IBindCtx* pBindCtx, IMoniker* pLeftMoniker, IMoniker* pNewlyRunning) throw() |
---|
384 | { |
---|
385 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
386 | _ATLTRY |
---|
387 | { |
---|
388 | return m_pMoniker->IsRunning(pBindCtx, pLeftMoniker, pNewlyRunning); |
---|
389 | } |
---|
390 | _ATLCATCH(Exception) |
---|
391 | { |
---|
392 | _C(Exception); |
---|
393 | } |
---|
394 | return S_OK; |
---|
395 | } |
---|
396 | STDMETHOD(GetTimeOfLastChange)(IBindCtx* pBindCtx, IMoniker* pLeftMoniker, FILETIME* pFileTime) throw() |
---|
397 | { |
---|
398 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
399 | _ATLTRY |
---|
400 | { |
---|
401 | return m_pMoniker->GetTimeOfLastChange(pBindCtx, pLeftMoniker, pFileTime); |
---|
402 | } |
---|
403 | _ATLCATCH(Exception) |
---|
404 | { |
---|
405 | _C(Exception); |
---|
406 | } |
---|
407 | return S_OK; |
---|
408 | } |
---|
409 | STDMETHOD(Inverse)(IMoniker** ppMoniker) throw() |
---|
410 | { |
---|
411 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
412 | _ATLTRY |
---|
413 | { |
---|
414 | return m_pMoniker->Inverse(ppMoniker); |
---|
415 | } |
---|
416 | _ATLCATCH(Exception) |
---|
417 | { |
---|
418 | _C(Exception); |
---|
419 | } |
---|
420 | return S_OK; |
---|
421 | } |
---|
422 | STDMETHOD(CommonPrefixWith)(IMoniker* pMoniker, IMoniker** ppPrefixMoniker) throw() |
---|
423 | { |
---|
424 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
425 | _ATLTRY |
---|
426 | { |
---|
427 | return m_pMoniker->CommonPrefixWith(pMoniker, ppPrefixMoniker); |
---|
428 | } |
---|
429 | _ATLCATCH(Exception) |
---|
430 | { |
---|
431 | _C(Exception); |
---|
432 | } |
---|
433 | return S_OK; |
---|
434 | } |
---|
435 | STDMETHOD(RelativePathTo)(IMoniker* pMoniker, IMoniker** ppRelativeMoniker) throw() |
---|
436 | { |
---|
437 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
438 | _ATLTRY |
---|
439 | { |
---|
440 | return m_pMoniker->RelativePathTo(pMoniker, ppRelativeMoniker); |
---|
441 | } |
---|
442 | _ATLCATCH(Exception) |
---|
443 | { |
---|
444 | _C(Exception); |
---|
445 | } |
---|
446 | return S_OK; |
---|
447 | } |
---|
448 | STDMETHOD(GetDisplayName)(IBindCtx* pBindCtx, IMoniker* pLeftMoniker, LPOLESTR* ppszDisplayName) throw() |
---|
449 | { |
---|
450 | _Z4(atlTraceCOM, 4, _T("pBindCtx 0x%p, pLeftMoniker 0x%p\n"), pBindCtx, pLeftMoniker); |
---|
451 | _ATLTRY |
---|
452 | { |
---|
453 | const HRESULT nResult = m_pMoniker->GetDisplayName(pBindCtx, pLeftMoniker, ppszDisplayName); |
---|
454 | if(SUCCEEDED(nResult)) |
---|
455 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x, *ppszDisplayName %s\n"), nResult, CString(*ppszDisplayName)); |
---|
456 | else |
---|
457 | _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); |
---|
458 | return nResult; |
---|
459 | } |
---|
460 | _ATLCATCH(Exception) |
---|
461 | { |
---|
462 | _C(Exception); |
---|
463 | } |
---|
464 | return S_OK; |
---|
465 | } |
---|
466 | STDMETHOD(ParseDisplayName)(IBindCtx* pBindCtx, IMoniker* pLeftMoniker, LPOLESTR pszDisplayName, ULONG* pnEatenLength, IMoniker** ppOutputMoniker) throw() |
---|
467 | { |
---|
468 | _Z4(atlTraceCOM, 4, _T("pBindCtx 0x%p, pLeftMoniker 0x%p, pszDisplayName %s\n"), pBindCtx, pLeftMoniker, CString(pszDisplayName)); |
---|
469 | _ATLTRY |
---|
470 | { |
---|
471 | return m_pMoniker->ParseDisplayName(pBindCtx, pLeftMoniker, pszDisplayName, pnEatenLength, ppOutputMoniker); |
---|
472 | } |
---|
473 | _ATLCATCH(Exception) |
---|
474 | { |
---|
475 | _C(Exception); |
---|
476 | } |
---|
477 | return S_OK; |
---|
478 | } |
---|
479 | STDMETHOD(IsSystemMoniker)(DWORD* pnSystemMonikerType) throw() |
---|
480 | { |
---|
481 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
482 | _ATLTRY |
---|
483 | { |
---|
484 | return m_pMoniker->IsSystemMoniker(pnSystemMonikerType); |
---|
485 | } |
---|
486 | _ATLCATCH(Exception) |
---|
487 | { |
---|
488 | _C(Exception); |
---|
489 | } |
---|
490 | return S_OK; |
---|
491 | } |
---|
492 | }; |
---|
493 | |
---|
494 | //////////////////////////////////////////////////////// |
---|
495 | // CEnumMoniker |
---|
496 | |
---|
497 | class ATL_NO_VTABLE CEnumMoniker : |
---|
498 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
499 | public IEnumMoniker |
---|
500 | { |
---|
501 | public: |
---|
502 | |
---|
503 | DECLARE_QI_TRACE(CEnumMoniker) |
---|
504 | |
---|
505 | BEGIN_COM_MAP(CEnumMoniker) |
---|
506 | COM_INTERFACE_ENTRY(IEnumMoniker) |
---|
507 | END_COM_MAP() |
---|
508 | |
---|
509 | private: |
---|
510 | CComPtr<IEnumMoniker> m_pEnumMoniker; |
---|
511 | |
---|
512 | public: |
---|
513 | // CEnumMoniker |
---|
514 | CEnumMoniker() |
---|
515 | { |
---|
516 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
517 | } |
---|
518 | ~CEnumMoniker() |
---|
519 | { |
---|
520 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
521 | } |
---|
522 | VOID Initialize(IEnumMoniker* pEnumMoniker) |
---|
523 | { |
---|
524 | _A(pEnumMoniker); |
---|
525 | _A(!m_pEnumMoniker); |
---|
526 | m_pEnumMoniker = pEnumMoniker; |
---|
527 | } |
---|
528 | |
---|
529 | // IEnumMoniker |
---|
530 | STDMETHOD(Next)(ULONG nElementCount, IMoniker** ppMoniker, ULONG* pnFetchedElementCount) throw() |
---|
531 | { |
---|
532 | _Z4(atlTraceCOM, 4, _T("nElementCount %d\n"), nElementCount); |
---|
533 | _ATLTRY |
---|
534 | { |
---|
535 | const HRESULT nNextResult = m_pEnumMoniker->Next(nElementCount, ppMoniker, pnFetchedElementCount); |
---|
536 | _Z4(atlTraceGeneral, 4, _T("nNextResult 0x%08x, *pnFetchedElementCount %s\n"), nNextResult, pnFetchedElementCount ? (LPCTSTR) AtlFormatString(_T("%d"), *pnFetchedElementCount) : _T("(null)")); |
---|
537 | if(SUCCEEDED(nNextResult)) |
---|
538 | { |
---|
539 | ULONG nFetchedElementCount = nElementCount; |
---|
540 | if(nNextResult != S_OK && pnFetchedElementCount) |
---|
541 | nFetchedElementCount = *pnFetchedElementCount; |
---|
542 | for(SIZE_T nIndex = 0; nIndex < nFetchedElementCount; nIndex++) |
---|
543 | { |
---|
544 | CComPtr<IMoniker>& pMoniker = reinterpret_cast<CComPtr<IMoniker>&>(ppMoniker[nIndex]); |
---|
545 | if(!pMoniker) |
---|
546 | break; |
---|
547 | CObjectPtr<CMoniker> pMonikerWrapper; |
---|
548 | pMonikerWrapper.Construct()->Initialize(pMoniker); |
---|
549 | pMoniker = pMonikerWrapper; |
---|
550 | } |
---|
551 | } |
---|
552 | return nNextResult; |
---|
553 | } |
---|
554 | _ATLCATCH(Exception) |
---|
555 | { |
---|
556 | _C(Exception); |
---|
557 | } |
---|
558 | return S_OK; |
---|
559 | } |
---|
560 | STDMETHOD(Skip)(ULONG nElementCount) throw() |
---|
561 | { |
---|
562 | _Z4(atlTraceCOM, 4, _T("nElementCount %d\n"), nElementCount); |
---|
563 | _ATLTRY |
---|
564 | { |
---|
565 | return m_pEnumMoniker->Skip(nElementCount); |
---|
566 | } |
---|
567 | _ATLCATCH(Exception) |
---|
568 | { |
---|
569 | _C(Exception); |
---|
570 | } |
---|
571 | return S_OK; |
---|
572 | } |
---|
573 | STDMETHOD(Reset)() throw() |
---|
574 | { |
---|
575 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
576 | _ATLTRY |
---|
577 | { |
---|
578 | return m_pEnumMoniker->Reset(); |
---|
579 | } |
---|
580 | _ATLCATCH(Exception) |
---|
581 | { |
---|
582 | _C(Exception); |
---|
583 | } |
---|
584 | return S_OK; |
---|
585 | } |
---|
586 | STDMETHOD(Clone)(IEnumMoniker** ppEnumMoniker) throw() |
---|
587 | { |
---|
588 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
589 | _ATLTRY |
---|
590 | { |
---|
591 | __C(m_pEnumMoniker->Clone(ppEnumMoniker)); |
---|
592 | CComPtr<IEnumMoniker>& pEnumMoniker = reinterpret_cast<CComPtr<IEnumMoniker>&>(*ppEnumMoniker); |
---|
593 | _A(pEnumMoniker); |
---|
594 | CObjectPtr<CEnumMoniker> pEnumMonikerWrapper; |
---|
595 | pEnumMonikerWrapper.Construct()->Initialize(pEnumMoniker); |
---|
596 | pEnumMoniker = pEnumMonikerWrapper; |
---|
597 | } |
---|
598 | _ATLCATCH(Exception) |
---|
599 | { |
---|
600 | _C(Exception); |
---|
601 | } |
---|
602 | return S_OK; |
---|
603 | } |
---|
604 | }; |
---|
605 | |
---|
606 | private: |
---|
607 | HINSTANCE m_hDevEnumModule; |
---|
608 | CComPtr<IUnknown> m_pSystemDeviceEnum; |
---|
609 | CComPtr<ICreateDevEnum> m_pCreateDevEnum; |
---|
610 | |
---|
611 | HRESULT QuerySystemDeviceEnumInterface(REFIID InterfaceIdentifier, VOID** ppvObject) |
---|
612 | { |
---|
613 | _A(InterfaceIdentifier == CLSID_SystemDeviceEnum); |
---|
614 | _A(ppvObject); |
---|
615 | *ppvObject = CComPtr<IUnknown>(m_pSystemDeviceEnum).Detach(); |
---|
616 | return S_OK; |
---|
617 | } |
---|
618 | static HRESULT WINAPI QuerySystemDeviceEnumInterface(VOID* pvInstance, REFIID InterfaceIdentifier, VOID** ppvObject, DWORD) |
---|
619 | { |
---|
620 | return ((CSystemDeviceEnumeratorSpy*) pvInstance)->QuerySystemDeviceEnumInterface(InterfaceIdentifier, ppvObject); |
---|
621 | } |
---|
622 | |
---|
623 | public: |
---|
624 | // CSystemDeviceEnumeratorSpyT |
---|
625 | static LPCTSTR GetOriginalLibraryName() throw() |
---|
626 | { |
---|
627 | return _T("devenum.dll"); |
---|
628 | } |
---|
629 | static CString GetObjectFriendlyName() |
---|
630 | { |
---|
631 | return _StringHelper::GetLine(T::IDR, 2); |
---|
632 | } |
---|
633 | static HRESULT WINAPI UpdateRegistry(BOOL bRegister) throw() |
---|
634 | { |
---|
635 | _Z2(atlTraceRegistrar, 2, _T("bRegister %d\n"), bRegister); |
---|
636 | _ATLTRY |
---|
637 | { |
---|
638 | TreatAsUpdateRegistryFromResource<T>(*t_pSystemDeviceEnumeratorClassIdentifier, bRegister); |
---|
639 | } |
---|
640 | _ATLCATCH(Exception) |
---|
641 | { |
---|
642 | _C(Exception); |
---|
643 | } |
---|
644 | return S_OK; |
---|
645 | } |
---|
646 | CSystemDeviceEnumeratorSpyT() throw() : |
---|
647 | m_hDevEnumModule(NULL) |
---|
648 | { |
---|
649 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
650 | } |
---|
651 | ~CSystemDeviceEnumeratorSpyT() throw() |
---|
652 | { |
---|
653 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
654 | } |
---|
655 | HRESULT FinalConstruct() throw() |
---|
656 | { |
---|
657 | _ATLTRY |
---|
658 | { |
---|
659 | TCHAR pszPath[MAX_PATH] = { 0 }; |
---|
660 | _W(GetModuleFileName(NULL, pszPath, DIM(pszPath))); |
---|
661 | _Z4(atlTraceRefcount, 4, _T("pszPath \"%s\", this 0x%08x, m_dwRef %d\n"), pszPath, this, m_dwRef); |
---|
662 | const HINSTANCE hModule = CoLoadLibrary(const_cast<LPOLESTR>((LPCOLESTR) CT2COLE(GetOriginalLibraryName())), TRUE); |
---|
663 | _ATLTRY |
---|
664 | { |
---|
665 | typedef HRESULT (WINAPI *DLLGETCLASSOBJECT)(REFCLSID, REFIID, VOID**); |
---|
666 | DLLGETCLASSOBJECT DllGetClassObject = (DLLGETCLASSOBJECT) GetProcAddress(hModule, "DllGetClassObject"); |
---|
667 | __E(DllGetClassObject); |
---|
668 | CComPtr<IClassFactory> pClassFactory; |
---|
669 | __C(DllGetClassObject(*t_pSystemDeviceEnumeratorClassIdentifier, __uuidof(IClassFactory), (VOID**) &pClassFactory)); |
---|
670 | _A(pClassFactory); |
---|
671 | CComPtr<IUnknown> pUnknown; |
---|
672 | __C(pClassFactory->CreateInstance(NULL, __uuidof(IUnknown), (VOID**) &pUnknown)); |
---|
673 | __D(pUnknown, E_NOINTERFACE); |
---|
674 | CComPtr<IUnknown> pSystemDeviceEnum; |
---|
675 | __C(pUnknown->QueryInterface(CLSID_SystemDeviceEnum, (VOID**) &pSystemDeviceEnum)); |
---|
676 | const CComQIPtr<ICreateDevEnum> pCreateDevEnum = pUnknown; |
---|
677 | __D(pCreateDevEnum, E_NOINTERFACE); |
---|
678 | m_pSystemDeviceEnum = pSystemDeviceEnum; |
---|
679 | m_pCreateDevEnum = pCreateDevEnum; |
---|
680 | } |
---|
681 | _ATLCATCHALL() |
---|
682 | { |
---|
683 | CoFreeLibrary(hModule); |
---|
684 | _ATLRETHROW; |
---|
685 | } |
---|
686 | _A(!m_hDevEnumModule); |
---|
687 | m_hDevEnumModule = hModule; |
---|
688 | } |
---|
689 | _ATLCATCH(Exception) |
---|
690 | { |
---|
691 | _C(Exception); |
---|
692 | } |
---|
693 | return S_OK; |
---|
694 | } |
---|
695 | VOID FinalRelease() throw() |
---|
696 | { |
---|
697 | _Z5(atlTraceRefcount, 5, _T("m_dwRef 0x%x\n"), m_dwRef); |
---|
698 | m_pSystemDeviceEnum = NULL; |
---|
699 | m_pCreateDevEnum = NULL; |
---|
700 | if(m_hDevEnumModule) |
---|
701 | { |
---|
702 | CoFreeLibrary(m_hDevEnumModule); |
---|
703 | m_hDevEnumModule = NULL; |
---|
704 | } |
---|
705 | } |
---|
706 | static CString FormatDeviceCategory(const GUID& DeviceCategory) |
---|
707 | { |
---|
708 | static const struct { const GUID* pIdentifier; LPCSTR pszName; } g_pMap[] = |
---|
709 | { |
---|
710 | #define A(x) { &x, #x }, |
---|
711 | A(CLSID_VideoInputDeviceCategory) |
---|
712 | A(CLSID_LegacyAmFilterCategory) |
---|
713 | A(CLSID_VideoCompressorCategory) |
---|
714 | A(CLSID_AudioCompressorCategory) |
---|
715 | A(CLSID_AudioInputDeviceCategory) |
---|
716 | A(CLSID_AudioRendererCategory) |
---|
717 | A(CLSID_MidiRendererCategory) |
---|
718 | A(CLSID_TransmitCategory) |
---|
719 | A(CLSID_DeviceControlCategory) |
---|
720 | A(CLSID_ActiveMovieCategories) |
---|
721 | A(CLSID_DVDHWDecodersCategory) |
---|
722 | A(CLSID_MediaEncoderCategory) |
---|
723 | A(CLSID_MediaMultiplexerCategory) |
---|
724 | #undef A |
---|
725 | }; |
---|
726 | for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++) |
---|
727 | if(*g_pMap[nIndex].pIdentifier == DeviceCategory) |
---|
728 | return CString(g_pMap[nIndex].pszName); |
---|
729 | return CString(_PersistHelper::StringFromIdentifier(DeviceCategory)); |
---|
730 | } |
---|
731 | |
---|
732 | // ISystemDeviceEnumeratorSpy |
---|
733 | |
---|
734 | // ICreateDevEnum |
---|
735 | STDMETHOD(CreateClassEnumerator)(REFCLSID DeviceCategory, IEnumMoniker** ppEnumMoniker, DWORD nFlags) throw() |
---|
736 | { |
---|
737 | _Z4(atlTraceCOM, 4, _T("DeviceCategory %s, nFlags 0x%x\n"), FormatDeviceCategory(DeviceCategory), nFlags); |
---|
738 | _ATLTRY |
---|
739 | { |
---|
740 | __C(m_pCreateDevEnum->CreateClassEnumerator(DeviceCategory, ppEnumMoniker, nFlags)); |
---|
741 | CComPtr<IEnumMoniker>& pEnumMoniker = reinterpret_cast<CComPtr<IEnumMoniker>&>(*ppEnumMoniker); |
---|
742 | if(pEnumMoniker) |
---|
743 | { |
---|
744 | #pragma region Trace Monikers |
---|
745 | __C(pEnumMoniker->Reset()); |
---|
746 | CComPtr<IMoniker> pMoniker; |
---|
747 | while(pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK) |
---|
748 | { |
---|
749 | _Z4(atlTraceCOM, 4, _T("pMoniker %ls\n"), _FilterGraphHelper::GetMonikerDisplayName(pMoniker)); |
---|
750 | CComPtr<IBindCtx> pBindCtx; |
---|
751 | __C(CreateBindCtx(0, &pBindCtx)); |
---|
752 | CComPtr<IPropertyBag> pPropertyBag; |
---|
753 | __C(pMoniker->BindToStorage(pBindCtx, NULL, __uuidof(IPropertyBag), (VOID**) &pPropertyBag)); |
---|
754 | const CStringW sFriendlyName = _FilterGraphHelper::ReadPropertyBagString(pPropertyBag, OLESTR("FriendlyName")); |
---|
755 | const CStringW sDescription = _FilterGraphHelper::ReadPropertyBagString(pPropertyBag, OLESTR("Description")); |
---|
756 | const CStringW sDevicePath = _FilterGraphHelper::ReadPropertyBagString(pPropertyBag, OLESTR("DevicePath")); |
---|
757 | _Z4(atlTraceCOM, 4, _T("sFriendlyName \"%ls\", sDescription \"%ls\", sDevicePath \"%ls\"\n"), sFriendlyName, sDescription, sDevicePath); |
---|
758 | pMoniker.Release(); |
---|
759 | } |
---|
760 | __C(pEnumMoniker->Reset()); |
---|
761 | #pragma endregion |
---|
762 | CObjectPtr<CEnumMoniker> pEnumMonikerWrapper; |
---|
763 | pEnumMonikerWrapper.Construct()->Initialize(pEnumMoniker); |
---|
764 | pEnumMoniker = pEnumMonikerWrapper; |
---|
765 | } |
---|
766 | } |
---|
767 | _ATLCATCH(Exception) |
---|
768 | { |
---|
769 | _C(Exception); |
---|
770 | } |
---|
771 | return S_OK; |
---|
772 | } |
---|
773 | }; |
---|
774 | |
---|
775 | //////////////////////////////////////////////////////////// |
---|
776 | // CSystemDeviceEnumeratorSpy |
---|
777 | |
---|
778 | class ATL_NO_VTABLE CSystemDeviceEnumeratorSpy : |
---|
779 | public CSystemDeviceEnumeratorSpyT<CSystemDeviceEnumeratorSpy, &CLSID_SystemDeviceEnum>, |
---|
780 | public CComCoClass<CSystemDeviceEnumeratorSpy, &CLSID_SystemDeviceEnumeratorSpy> |
---|
781 | { |
---|
782 | public: |
---|
783 | enum { IDR = IDR_SYSTEMDEVICEENUMERATORSPY }; |
---|
784 | |
---|
785 | private: |
---|
786 | static LPCTSTR g_pszClassName; |
---|
787 | |
---|
788 | public: |
---|
789 | //typedef CBlackListAwareComCreatorT<CComObjectCached<CSystemDeviceEnumeratorSpy>, CSystemDeviceEnumeratorSpy, &g_pszClassName> _ClassFactoryCreatorClass; // DECLARE_CLASSFACTORY override |
---|
790 | typedef CComCreator2<CBlackListAwareComCreatorT<CComObject<CSystemDeviceEnumeratorSpy>, CSystemDeviceEnumeratorSpy, &g_pszClassName>, CBlackListAwareComCreatorT<CComAggObject<CSystemDeviceEnumeratorSpy>, CSystemDeviceEnumeratorSpy, &g_pszClassName> > _CreatorClass; // DECLARE_AGGREGATABLE override |
---|
791 | |
---|
792 | public: |
---|
793 | // CSystemDeviceEnumeratorSpy |
---|
794 | }; |
---|
795 | |
---|
796 | __declspec(selectany) LPCTSTR CSystemDeviceEnumeratorSpy::g_pszClassName = _T("CSystemDeviceEnumeratorSpy"); |
---|
797 | |
---|
798 | OBJECT_ENTRY_AUTO(__uuidof(SystemDeviceEnumeratorSpy), CSystemDeviceEnumeratorSpy) |
---|