source: trunk/DirectShowSpy/Configuration.cpp @ 795

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

Fixed small glitch in helper UI; added missing CLSID to UnregisterTreatAsClasses? export

  • Property svn:keywords set to Id
File size: 4.3 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                        &CLSID_FilterGraphPrivateThread, // CLSID_PrivateThreadSpy
44                };
45                CProcessTokenPrivileges ProcessTokenPrivileges;
46                BOOL bProcessTokenPrivilegesAdjustNeeded = TRUE;
47                for(SIZE_T nIndex = 0; nIndex < DIM(g_ppClassIdentifiers); nIndex++)
48                {
49                        const CLSID& ClassIdentifier = *g_ppClassIdentifiers[nIndex];
50                        _Z4(atlTraceGeneral, 4, _T("nIndex %d, ClassIdentifier %ls\n"), nIndex, _PersistHelper::StringFromIdentifier(ClassIdentifier));
51                        _ATLTRY
52                        {
53                                CLSID CurrentTreatAsClassIdentifier = CLSID_NULL;
54                                const HRESULT nCoGetTreatAsClassResult = CoGetTreatAsClass(ClassIdentifier, &CurrentTreatAsClassIdentifier);
55                                _Z4_HRESULT(nCoGetTreatAsClassResult);
56                                __C(nCoGetTreatAsClassResult);
57                                if(nCoGetTreatAsClassResult != S_OK)
58                                        continue;
59                                _Z4(atlTraceGeneral, 4, _T("CurrentTreatAsClassIdentifier %ls\n"), _PersistHelper::StringFromIdentifier(CurrentTreatAsClassIdentifier));
60                                #pragma region Adjust
61                                if(bProcessTokenPrivilegesAdjustNeeded)
62                                {
63                                        bProcessTokenPrivilegesAdjustNeeded = FALSE;
64                                        if(IsWindowsVistaOrGreater())
65                                                _ATLTRY
66                                                {
67                                                        ProcessTokenPrivileges.Adjust();
68                                                }
69                                                _ATLCATCHALL()
70                                                {
71                                                        _Z_EXCEPTION();
72                                                }
73                                }
74                                #pragma endregion
75                                CClassIdentifierRegKeySecurity ClassIdentifierRegKeySecurity(ClassIdentifier);
76                                if(IsWindowsVistaOrGreater())
77                                        ClassIdentifierRegKeySecurity.Adjust();
78                                const HRESULT nCoTreatAsClassResult = CoTreatAsClass(ClassIdentifier, CLSID_NULL);
79                                _Z4_HRESULT(nCoTreatAsClassResult);
80                                __C(nCoTreatAsClassResult);
81                        }
82                        _ATLCATCHALL()
83                        {
84                                _Z_EXCEPTION();
85                        }
86                }
87        }
88        _ATLCATCH(Exception)
89        {
90                _C(Exception);
91        }
92        return S_OK;
93}
94
95////////////////////////////////////////////////////////////
96// DoRegistrationPropertySheetModal
97
98#if defined(_WIN64)
99        extern "C" __declspec(dllexport) 
100#else
101        #pragma comment(linker, "/EXPORT:DoRegistrationPropertySheetModal=_DoRegistrationPropertySheetModal@16,PRIVATE")
102        extern "C" // __declspec(dllexport)
103#endif // defined(_WIN64)
104
105HRESULT STDMETHODCALLTYPE DoRegistrationPropertySheetModal(HWND hParentWindow, HINSTANCE, LPSTR pszCommandLine, INT nShowCommand)
106{
107        hParentWindow; pszCommandLine; nShowCommand;
108        _ATLTRY
109        {
110                CSingleThreadedApartment SingleThreadedApartment;
111                _W(AtlInitCommonControls(ICC_WIN95_CLASSES | ICC_COOL_CLASSES | ICC_STANDARD_CLASSES));
112                CRegistrationPropertySheet PropertySheet;
113                PropertySheet.DoModal(GetActiveWindow());
114        }
115        _ATLCATCH(Exception)
116        {
117                _C(Exception);
118        }
119        return S_OK;
120}
Note: See TracBrowser for help on using the repository browser.