source: trunk/DirectShowSpy/Configuration.cpp @ 617

Last change on this file since 617 was 617, checked in by roman, 8 years ago

Exported function signatures replaced to accurately rundll32 compatible; added IModuleVersionInformation implementation to FilterGraphHelper?; added debug Host01 project; IFilterGraphHelper interface is extended with MediaSampleTrace? related automation methods; MediaSampleTrace? UI is extended to support data load from external file

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2008-2015
3// Created by Roman Ryltsov roman@alax.info, http://alax.info
4//
5// This source code is published to complement DirectShowSpy developer powertoy
6// and demonstrate the internal use of APIs and tricks powering the tool. It is
7// allowed to freely re-use the portions of the code in other projects, commercial
8// or otherwise (provided that you don’t pretend that you wrote the original tool).
9//
10// Please keep in mind that DirectShowSpy is a developer tool, it is strongly recommended
11// that it is not shipped with release grade software. It is allowed to distribute
12// DirectShowSpy if only it is not registered with Windows by default and either
13// used privately, or registered on specific throubleshooting request. The advice applies
14// to hooking methods used by DirectShowSpy in general as well.
15
16#include "stdafx.h"
17#include <dshow.h>
18#include "resource.h"
19#include "Common.h"
20#include "Configuration.h"
21
22////////////////////////////////////////////////////////////
23// UnregisterTreatAsClasses
24
25#if defined(_WIN64)
26        extern "C" __declspec(dllexport) 
27#else
28        #pragma comment(linker, "/EXPORT:UnregisterTreatAsClasses=_UnregisterTreatAsClasses@16,PRIVATE")
29        extern "C" // __declspec(dllexport)
30#endif // defined(_WIN64)
31
32HRESULT STDMETHODCALLTYPE UnregisterTreatAsClasses(HWND hParentWindow, HINSTANCE, LPSTR pszCommandLine, INT nShowCommand)
33{
34        hParentWindow; pszCommandLine; nShowCommand;
35        _ATLTRY
36        {
37                static const CLSID* g_ppClassIdentifiers[] = 
38                {
39                        &CLSID_FilterMapper2, // CFilterMapperSpy
40                        &CLSID_SystemDeviceEnum, // CLSID_SystemDeviceEnumeratorSpy
41                        &CLSID_FilterGraph, // CLSID_Spy
42                        &CLSID_FilterGraphNoThread, // CLSID_NoThreadSpy
43                };
44                CProcessTokenPrivileges ProcessTokenPrivileges;
45                BOOL bProcessTokenPrivilegesAdjustNeeded = TRUE;
46                for(SIZE_T nIndex = 0; nIndex < DIM(g_ppClassIdentifiers); nIndex++)
47                {
48                        const CLSID& ClassIdentifier = *g_ppClassIdentifiers[nIndex];
49                        _Z4(atlTraceGeneral, 4, _T("nIndex %d, ClassIdentifier %ls\n"), nIndex, _PersistHelper::StringFromIdentifier(ClassIdentifier));
50                        _ATLTRY
51                        {
52                                CLSID CurrentTreatAsClassIdentifier = CLSID_NULL;
53                                const HRESULT nCoGetTreatAsClassResult = CoGetTreatAsClass(ClassIdentifier, &CurrentTreatAsClassIdentifier);
54                                _Z4_HRESULT(nCoGetTreatAsClassResult);
55                                __C(nCoGetTreatAsClassResult);
56                                if(nCoGetTreatAsClassResult != S_OK)
57                                        continue;
58                                _Z4(atlTraceGeneral, 4, _T("CurrentTreatAsClassIdentifier %ls\n"), _PersistHelper::StringFromIdentifier(CurrentTreatAsClassIdentifier));
59                                #pragma region Adjust
60                                if(bProcessTokenPrivilegesAdjustNeeded)
61                                {
62                                        bProcessTokenPrivilegesAdjustNeeded = FALSE;
63                                        if(IsWindowsVistaOrGreater())
64                                                _ATLTRY
65                                                {
66                                                        ProcessTokenPrivileges.Adjust();
67                                                }
68                                                _ATLCATCHALL()
69                                                {
70                                                        _Z_EXCEPTION();
71                                                }
72                                }
73                                #pragma endregion
74                                CClassIdentifierRegKeySecurity ClassIdentifierRegKeySecurity(ClassIdentifier);
75                                if(IsWindowsVistaOrGreater())
76                                        ClassIdentifierRegKeySecurity.Adjust();
77                                const HRESULT nCoTreatAsClassResult = CoTreatAsClass(ClassIdentifier, CLSID_NULL);
78                                _Z4_HRESULT(nCoTreatAsClassResult);
79                                __C(nCoTreatAsClassResult);
80                        }
81                        _ATLCATCHALL()
82                        {
83                                _Z_EXCEPTION();
84                        }
85                }
86        }
87        _ATLCATCH(Exception)
88        {
89                _C(Exception);
90        }
91        return S_OK;
92}
93
94////////////////////////////////////////////////////////////
95// DoRegistrationPropertySheetModal
96
97#if defined(_WIN64)
98        extern "C" __declspec(dllexport) 
99#else
100        #pragma comment(linker, "/EXPORT:DoRegistrationPropertySheetModal=_DoRegistrationPropertySheetModal@16,PRIVATE")
101        extern "C" // __declspec(dllexport)
102#endif // defined(_WIN64)
103
104HRESULT STDMETHODCALLTYPE DoRegistrationPropertySheetModal(HWND hParentWindow, HINSTANCE, LPSTR pszCommandLine, INT nShowCommand)
105{
106        hParentWindow; pszCommandLine; nShowCommand;
107        _ATLTRY
108        {
109                CSingleThreadedApartment SingleThreadedApartment;
110                _W(AtlInitCommonControls(ICC_WIN95_CLASSES | ICC_COOL_CLASSES | ICC_STANDARD_CLASSES));
111                CRegistrationPropertySheet PropertySheet;
112                PropertySheet.DoModal(GetActiveWindow());
113        }
114        _ATLCATCH(Exception)
115        {
116                _C(Exception);
117        }
118        return S_OK;
119}
Note: See TracBrowser for help on using the repository browser.