1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2013 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | |
---|
5 | #include "stdafx.h" |
---|
6 | #include <dshow.h> |
---|
7 | #include "resource.h" |
---|
8 | #include "Common.h" |
---|
9 | #include "Configuration.h" |
---|
10 | |
---|
11 | //////////////////////////////////////////////////////////// |
---|
12 | // UnregisterTreatAsClasses |
---|
13 | |
---|
14 | #if defined(_WIN64) |
---|
15 | extern "C" __declspec(dllexport) |
---|
16 | #else |
---|
17 | #pragma comment(linker, "/EXPORT:UnregisterTreatAsClasses=_UnregisterTreatAsClasses@0,PRIVATE") |
---|
18 | extern "C" // __declspec(dllexport) |
---|
19 | #endif // defined(_WIN64) |
---|
20 | |
---|
21 | HRESULT STDMETHODCALLTYPE UnregisterTreatAsClasses() throw() |
---|
22 | { |
---|
23 | _ATLTRY |
---|
24 | { |
---|
25 | static const CLSID* g_ppClassIdentifiers[] = |
---|
26 | { |
---|
27 | &CLSID_FilterMapper2, // CFilterMapperSpy |
---|
28 | &CLSID_SystemDeviceEnum, // CLSID_SystemDeviceEnumeratorSpy |
---|
29 | &CLSID_FilterGraph, // CLSID_Spy |
---|
30 | &CLSID_FilterGraphNoThread, // CLSID_NoThreadSpy |
---|
31 | }; |
---|
32 | const ULONG nOsVersion = GetOsVersion(); |
---|
33 | _Z4(atlTraceGeneral, 4, _T("nOsVersion 0x%08x\n"), nOsVersion); |
---|
34 | CProcessTokenPrivileges ProcessTokenPrivileges; |
---|
35 | BOOL bProcessTokenPrivilegesAdjustNeeded = TRUE; |
---|
36 | for(SIZE_T nIndex = 0; nIndex < DIM(g_ppClassIdentifiers); nIndex++) |
---|
37 | { |
---|
38 | const CLSID& ClassIdentifier = *g_ppClassIdentifiers[nIndex]; |
---|
39 | _Z4(atlTraceGeneral, 4, _T("nIndex %d, ClassIdentifier %ls\n"), nIndex, _PersistHelper::StringFromIdentifier(ClassIdentifier)); |
---|
40 | _ATLTRY |
---|
41 | { |
---|
42 | CLSID CurrentTreatAsClassIdentifier = CLSID_NULL; |
---|
43 | const HRESULT nCoGetTreatAsClassResult = CoGetTreatAsClass(ClassIdentifier, &CurrentTreatAsClassIdentifier); |
---|
44 | _Z4_HRESULT(nCoGetTreatAsClassResult); |
---|
45 | __C(nCoGetTreatAsClassResult); |
---|
46 | if(nCoGetTreatAsClassResult != S_OK) |
---|
47 | continue; |
---|
48 | _Z4(atlTraceGeneral, 4, _T("CurrentTreatAsClassIdentifier %ls\n"), _PersistHelper::StringFromIdentifier(CurrentTreatAsClassIdentifier)); |
---|
49 | #pragma region Adjust |
---|
50 | if(bProcessTokenPrivilegesAdjustNeeded) |
---|
51 | { |
---|
52 | bProcessTokenPrivilegesAdjustNeeded = FALSE; |
---|
53 | if(nOsVersion >= 0x060000) // Win Vista+ |
---|
54 | _ATLTRY |
---|
55 | { |
---|
56 | ProcessTokenPrivileges.Adjust(); |
---|
57 | } |
---|
58 | _ATLCATCHALL() |
---|
59 | { |
---|
60 | _Z_EXCEPTION(); |
---|
61 | } |
---|
62 | } |
---|
63 | #pragma endregion |
---|
64 | CClassIdentifierRegKeySecurity ClassIdentifierRegKeySecurity(ClassIdentifier); |
---|
65 | if(nOsVersion >= 0x060000) // Win Vista+ |
---|
66 | ClassIdentifierRegKeySecurity.Adjust(); |
---|
67 | const HRESULT nCoTreatAsClassResult = CoTreatAsClass(ClassIdentifier, CLSID_NULL); |
---|
68 | _Z4_HRESULT(nCoTreatAsClassResult); |
---|
69 | __C(nCoTreatAsClassResult); |
---|
70 | } |
---|
71 | _ATLCATCHALL() |
---|
72 | { |
---|
73 | _Z_EXCEPTION(); |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | _ATLCATCH(Exception) |
---|
78 | { |
---|
79 | _C(Exception); |
---|
80 | } |
---|
81 | return S_OK; |
---|
82 | } |
---|
83 | |
---|
84 | //////////////////////////////////////////////////////////// |
---|
85 | // DoRegistrationPropertySheetModal |
---|
86 | |
---|
87 | #if defined(_WIN64) |
---|
88 | extern "C" __declspec(dllexport) |
---|
89 | #else |
---|
90 | #pragma comment(linker, "/EXPORT:DoRegistrationPropertySheetModal=_DoRegistrationPropertySheetModal@0,PRIVATE") |
---|
91 | extern "C" // __declspec(dllexport) |
---|
92 | #endif // defined(_WIN64) |
---|
93 | |
---|
94 | HRESULT STDMETHODCALLTYPE DoRegistrationPropertySheetModal() throw() |
---|
95 | { |
---|
96 | _ATLTRY |
---|
97 | { |
---|
98 | CSingleThreadedApartment SingleThreadedApartment; |
---|
99 | _W(AtlInitCommonControls(ICC_WIN95_CLASSES | ICC_COOL_CLASSES | ICC_STANDARD_CLASSES)); |
---|
100 | CRegistrationPropertySheet PropertySheet; |
---|
101 | PropertySheet.DoModal(GetActiveWindow()); |
---|
102 | } |
---|
103 | _ATLCATCH(Exception) |
---|
104 | { |
---|
105 | _C(Exception); |
---|
106 | } |
---|
107 | return S_OK; |
---|
108 | } |
---|