Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9.1, 0.9.1.1, and 0.9.2

stable shellext: new template class ThgClassFactory

Changeset a6817b2ccc9a

Parent acedf4c93aab

by Adrian Buehlmann

Changes to 3 files · Browse files at a6817b2ccc9a Showing diff from parent acedf4c93aab Diff from another changeset...

 
3
4
5
 
 
6
7
8
 
75
76
77
 
 
78
79
80
81
 
82
83
84
85
86
87
88
89
 
90
91
92
93
94
95
96
97
 
98
99
100
101
102
103
104
105
 
106
107
108
 
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
 
232
233
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
236
237
 
3
4
5
6
7
8
9
10
 
77
78
79
80
81
82
83
 
 
84
85
86
87
88
89
90
 
 
91
92
93
94
95
96
97
 
 
98
99
100
101
102
103
104
 
 
105
106
107
108
 
124
125
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
128
129
 
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
@@ -3,6 +3,8 @@
 #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "InitStatus.h" +#include "ThgClassFactory.h" +  #include <olectl.h>    #define INITGUID @@ -75,34 +77,32 @@
  TDEBUG_TRACE("DllGetClassObject clsid = " << WideToMultibyte(pwszShellExt));   *ppvOut = NULL;   + typedef ThgClassFactory<CShellExt> Fact; +   if (IsEqualIID(rclsid, CLSID_TortoiseHg0))   { - CDllRegSxClassFactory *pcf = - new CDllRegSxClassFactory('C'); // clean + Fact *pcf = new Fact('C'); // clean   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg0");   ++InitStatus::inst().unchanged_;   return pcf->QueryInterface(riid, ppvOut);   }   else if (IsEqualIID(rclsid, CLSID_TortoiseHg1))   { - CDllRegSxClassFactory *pcf = - new CDllRegSxClassFactory('A'); // added + Fact *pcf = new Fact('A'); // added   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg1");   ++InitStatus::inst().added_;   return pcf->QueryInterface(riid, ppvOut);   }   else if (IsEqualIID(rclsid, CLSID_TortoiseHg2))   { - CDllRegSxClassFactory *pcf = - new CDllRegSxClassFactory('M'); // modified + Fact *pcf = new Fact('M'); // modified   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg2");   ++InitStatus::inst().modified_;   return pcf->QueryInterface(riid, ppvOut);   }   else if (IsEqualIID(rclsid, CLSID_TortoiseHg6))   { - CDllRegSxClassFactory *pcf = - new CDllRegSxClassFactory('?'); // not in repo + Fact *pcf = new Fact('?'); // not in repo   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg6");   ++InitStatus::inst().notinrepo_;   return pcf->QueryInterface(riid, ppvOut); @@ -124,84 +124,6 @@
 }     -LPCRITICAL_SECTION CDllRegSxClassFactory::GetCriticalSection() -{ - return &g_critical_section; -} - - -CDllRegSxClassFactory::CDllRegSxClassFactory(char classToMake) : - myclassToMake(classToMake) -{ - ThgCriticalSection cs(GetCriticalSection()); - m_cRef = 0L; - g_cRefThisDll++; -} - - -CDllRegSxClassFactory::~CDllRegSxClassFactory() -{ - ThgCriticalSection cs(GetCriticalSection()); - g_cRefThisDll--; -} - - -STDMETHODIMP CDllRegSxClassFactory::QueryInterface( - REFIID riid, LPVOID FAR* ppv) -{ - *ppv = NULL; - - if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)) - { - *ppv = (LPCLASSFACTORY) this; - AddRef(); - return NOERROR; - } - - return E_NOINTERFACE; -} - - -STDMETHODIMP_(ULONG) CDllRegSxClassFactory::AddRef() -{ - ThgCriticalSection cs(GetCriticalSection()); - return ++m_cRef; -} - - -STDMETHODIMP_(ULONG) CDllRegSxClassFactory::Release() -{ - ThgCriticalSection cs(GetCriticalSection()); - if (--m_cRef) - return m_cRef; - - delete this; - return 0L; -} - - -STDMETHODIMP CDllRegSxClassFactory::CreateInstance( - LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppvObj) -{ - *ppvObj = NULL; - - if (pUnkOuter) - return CLASS_E_NOAGGREGATION; - - LPCSHELLEXT pShellExt = new CShellExt(myclassToMake); - if (NULL == pShellExt) - return E_OUTOFMEMORY; - - return pShellExt->QueryInterface(riid, ppvObj); -} - - -STDMETHODIMP CDllRegSxClassFactory::LockServer(BOOL fLock) -{ - return NOERROR; -} - -  CShellExt::CShellExt(char tortoiseClass) :   myTortoiseClass(tortoiseClass),   m_ppszFileUserClickedOn(0) @@ -232,6 +154,20 @@
 }     +void CShellExt::IncDllRef() +{ + ThgCriticalSection cs(GetCriticalSection()); + g_cRefThisDll++; +} + + +void CShellExt::DecDllRef() +{ + ThgCriticalSection cs(GetCriticalSection()); + g_cRefThisDll--; +} + +  STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR* ppv)  {   *ppv = NULL;
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
43
44
45
 
 
46
47
48
 
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
 
22
23
24
25
26
27
28
29
@@ -5,27 +5,6 @@
 #include <string>     -class CDllRegSxClassFactory: public IClassFactory -{ - protected: - ULONG m_cRef; - const char myclassToMake; - - public: - explicit CDllRegSxClassFactory(char classToMake); - ~CDllRegSxClassFactory(); - - static LPCRITICAL_SECTION GetCriticalSection(); - - STDMETHODIMP QueryInterface(REFIID, LPVOID FAR*); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - - STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR*); - STDMETHODIMP LockServer(BOOL); -}; - -  class CShellExt:   public IContextMenu3, IShellIconOverlayIdentifier, IShellExtInit  { @@ -43,6 +22,8 @@
    public:   static LPCRITICAL_SECTION GetCriticalSection(); + static void IncDllRef(); + static void DecDllRef();     explicit CShellExt(char Class);   ~CShellExt();
Change 1 of 1 Show Entire File win32/​shellext/​ThgClassFactory.h Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@@ -0,0 +1,86 @@
+#ifndef _ThgClassFactory_h_ +#define _ThgClassFactory_h_ + +#include "ShellExt.h" + + +template <class T> +class ThgClassFactory: public IClassFactory +{ + ULONG m_cRef; + const char myclassToMake; + +public: + explicit ThgClassFactory(char classToMake) : + myclassToMake(classToMake) + { + CShellExt::IncDllRef(); + m_cRef = 0L; + } + + + ~ThgClassFactory() + { + CShellExt::DecDllRef(); + } + + + STDMETHODIMP QueryInterface( + REFIID riid, LPVOID FAR* ppv) + { + *ppv = NULL; + + if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)) + { + *ppv = (LPCLASSFACTORY) this; + AddRef(); + return NOERROR; + } + + return E_NOINTERFACE; + } + + + STDMETHODIMP_(ULONG) AddRef() + { + ThgCriticalSection cs(CShellExt::GetCriticalSection()); + return ++m_cRef; + } + + + STDMETHODIMP_(ULONG) Release() + { + ThgCriticalSection cs(CShellExt::GetCriticalSection()); + if (--m_cRef) + return m_cRef; + + delete this; + return 0L; + } + + + STDMETHODIMP CreateInstance( + LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppvObj) + { + *ppvObj = NULL; + + if (pUnkOuter) + return CLASS_E_NOAGGREGATION; + + T *pShellExt = new T(myclassToMake); + if (NULL == pShellExt) + return E_OUTOFMEMORY; + + return pShellExt->QueryInterface(riid, ppvObj); + } + + + STDMETHODIMP LockServer(BOOL fLock) + { + return NOERROR; + } + +}; + + +#endif