source: trunk/DirectShowSpy/EnumerateRunningFilterGraphFilters/EnumerateRunningFilterGraphFilters.cpp @ 171

Last change on this file since 171 was 95, checked in by roman, 12 years ago

DirectShowSpy? moved from Assembla

  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2008-2009
3// Created by Roman Ryltsov roman@alax.info
4//
5// $Id: EnumerateRunningFilterGraphFilters.cpp 95 2012-08-17 17:21:13Z roman $
6
7#include "stdafx.h"
8#include <dshow.h>
9
10inline VOID ATLENSURE_THROW3(BOOL bResult, HRESULT nCode, LPCSTR pszFile, INT nLine)
11{
12        if(!bResult)
13                _tprintf(_T("Warning, %hs(%d): Error 0x%08x\n"), strrchr(pszFile, '\\') + 1, nLine, nCode);
14        ATLENSURE_THROW(bResult, nCode);
15}
16
17inline VOID ATLENSURE_THROW3(const VOID* pvResult, HRESULT nCode, LPCSTR pszFile, INT nLine)
18{
19        return ATLENSURE_THROW3(pvResult != NULL, nCode, pszFile, nLine);
20}
21
22#define ATLENSURE_THROW2(bResult, nCode) ATLENSURE_THROW3(bResult, nCode, __FILE__, __LINE__)
23
24inline VOID ATLENSURE_SUCCEEDED3(HRESULT nResult, LPCSTR pszFile, INT nLine)
25{
26        if(FAILED(nResult))
27                _tprintf(_T("Warning, %hs(%d): Error 0x%08x\n"), strrchr(pszFile, '\\') + 1, nLine, nResult);
28        ATLENSURE_SUCCEEDED(nResult);
29}
30
31#define ATLENSURE_SUCCEEDED2(nResult) ATLENSURE_SUCCEEDED3(nResult, __FILE__, __LINE__)
32
33int _tmain(int argc, _TCHAR* argv[])
34{
35        _ATLTRY
36        {
37                ATLENSURE_SUCCEEDED2(CoInitialize(NULL));
38                _ATLTRY
39                {
40#if !defined(_DEBUG)
41                        MessageBox(NULL, _T("Before GetRunningObjectTable"), _T("Debug"), MB_OK);
42#endif // !defined(_DEBUG);
43                        CComPtr<IRunningObjectTable> pRunningObjectTable;
44                        ATLENSURE_SUCCEEDED2(GetRunningObjectTable(0, &pRunningObjectTable));
45                        CComPtr<IEnumMoniker> pEnumMoniker;
46                        ATLENSURE_SUCCEEDED2(pRunningObjectTable->EnumRunning(&pEnumMoniker));
47                        CComPtr<IMalloc> pMalloc;
48                        ATLENSURE_SUCCEEDED2(CoGetMalloc(1, &pMalloc));
49                        CComPtr<IMoniker> pMoniker;
50                        for(; ; )
51                        {
52                                const HRESULT nNextResult = pEnumMoniker->Next(1, &pMoniker, NULL);
53                                ATLENSURE_SUCCEEDED2(nNextResult);
54                                if(nNextResult != S_OK)
55                                        break;
56                                _ATLTRY
57                                {
58                                        CComPtr<IBindCtx> pBindCtx;
59                                        ATLENSURE_SUCCEEDED2(CreateBindCtx(0, &pBindCtx));
60                                        LPOLESTR pszDisplayName = NULL;
61                                        ATLENSURE_SUCCEEDED2(pMoniker->GetDisplayName(pBindCtx, NULL, &pszDisplayName));
62                                        _tprintf(_T("ROT Moniker Display Name: %ls\n"), pszDisplayName);
63                                        const BOOL bFilterGraph = _wcsnicmp(pszDisplayName, L"!FilterGraph", 12) == 0;
64                                        pMalloc->Free(pszDisplayName);
65                                        if(bFilterGraph)
66                                        {
67#define IMyFilterGraph IFilterGraph //IGraphBuilder
68                                                CComQIPtr<IMyFilterGraph> pFilterGraph;
69                                                //ATLENSURE_SUCCEEDED2(pMoniker->BindToObject(pBindCtx, NULL, __uuidof(IMyFilterGraph), (VOID**) &pFilterGraph));
70                                                CComPtr<IUnknown> pFilterGraphUnknown;
71                                                ATLENSURE_SUCCEEDED2(pRunningObjectTable->GetObject(pMoniker, &pFilterGraphUnknown));
72#if !defined(_DEBUG)
73                                                MessageBox(NULL, _T("Before QueryInterface(IFilterGraph)"), _T("Debug"), MB_OK);
74#endif // !defined(_DEBUG);
75                                                pFilterGraph = pFilterGraphUnknown;
76#if !defined(_DEBUG)
77                                                MessageBox(NULL, _T("After QueryInterface(IFilterGraph)"), _T("Debug"), MB_OK);
78#endif // !defined(_DEBUG);
79                                                ATLENSURE_THROW2(pFilterGraph, E_NOINTERFACE);
80                                                CComPtr<IEnumFilters> pEnumFilters;
81                                                ATLENSURE_SUCCEEDED2(pFilterGraph->EnumFilters(&pEnumFilters));
82                                                CComPtr<IBaseFilter> pBaseFilter;
83                                                for(; ; )
84                                                {
85                                                        ULONG nFetchedCount = 0;
86                                                        const HRESULT nNextResult = pEnumFilters->Next(1, &pBaseFilter, &nFetchedCount);
87                                                        ATLENSURE_SUCCEEDED2(nNextResult);
88                                                        if(nNextResult != S_OK)
89                                                                break;
90                                                        ATLASSERT(nFetchedCount == 1);
91                                                        _ATLTRY
92                                                        {
93                                                                FILTER_INFO FilterInformation;
94                                                                ZeroMemory(&FilterInformation, sizeof FilterInformation);
95                                                                ATLENSURE_SUCCEEDED2(pBaseFilter->QueryFilterInfo(&FilterInformation));
96                                                                CComPtr<IFilterGraph> pFilterGraph;
97                                                                pFilterGraph.Attach(FilterInformation.pGraph);
98                                                                _tprintf(_T("ROT Filter Graph Filter Name: %ls\n"), FilterInformation.achName);
99                                                        }
100                                                        _ATLCATCH(Exception)
101                                                        {
102                                                                _tprintf(_T("Error 0x%08x\n"), (HRESULT) Exception);
103                                                        }
104                                                        pBaseFilter.Release();
105                                                }
106                                        }
107                                }
108                                _ATLCATCH(Exception)
109                                {
110                                        _tprintf(_T("Error 0x%08x\n"), (HRESULT) Exception);
111                                }
112                                pMoniker.Release();
113                        }
114                        MessageBox(NULL, _T("After Everything"), _T("Debug"), MB_OK);
115                }
116                _ATLCATCHALL()
117                {
118                        CoUninitialize();
119                        _ATLRETHROW;
120                }
121                CoUninitialize();
122        }
123        _ATLCATCH(Exception)
124        {
125                _tprintf(_T("Fatal Error 0x%08x\n"), (HRESULT) Exception);
126        }
127        _ATLCATCHALL()
128        {
129                _tprintf(_T("Fatal Error\n"));
130        }
131        return 0;
132}
133
Note: See TracBrowser for help on using the repository browser.