Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1.2 and tip

stable shellext: clean up code

Changeset eada6f0527b8

Parent c2050ce0c6de

by David Golub

Changes to 2 files · Browse files at eada6f0527b8 Showing diff from parent c2050ce0c6de Diff from another changeset...

 
20
21
22
23
24
25
26
27
28
 
 
 
29
30
31
 
40
41
42
43
44
 
45
46
47
48
49
50
 
 
51
52
53
54
55
56
 
57
58
59
 
64
65
66
67
 
68
69
70
 
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
 
20
21
22
 
 
 
 
 
 
23
24
25
26
27
28
 
37
38
39
 
 
40
41
42
43
44
 
 
45
46
47
48
49
50
51
 
52
53
54
55
 
60
61
62
 
63
64
65
66
 
141
142
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -20,12 +20,9 @@
 #define CLSID_TortoiseHgModified TOLSTR2(THG_CLSID_TortoiseHgModified)  #define CLSID_TortoiseHgUnversioned TOLSTR2(THG_CLSID_TortoiseHgUnversioned)   - -UINT g_cRefThisDll = 0; -HINSTANCE g_hmodThisDll = NULL; - -CRITICAL_SECTION g_critical_section; - +CRITICAL_SECTION CShellExt::cs_; +HMODULE CShellExt::hModule_ = NULL; +UINT CShellExt::cRef_ = 0;    typedef struct  { @@ -40,20 +37,19 @@
 VOID _UnloadResources();     -extern "C" -int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) +BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)  {   if (dwReason == DLL_PROCESS_ATTACH)   {   TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH"); - g_hmodThisDll = hInstance; - ::InitializeCriticalSection(&g_critical_section); + CShellExt::hModule_ = hInstance; + ::InitializeCriticalSection(CShellExt::GetCriticalSection());   _LoadResources();   }   else if (dwReason == DLL_PROCESS_DETACH)   {   TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH"); - ::DeleteCriticalSection(&g_critical_section); + ::DeleteCriticalSection(CShellExt::GetCriticalSection());   _UnloadResources();   }   @@ -64,7 +60,7 @@
 STDAPI DllCanUnloadNow(void)  {   TDEBUG_TRACE("DllCanUnloadNow"); - return (g_cRefThisDll == 0 ? S_OK : S_FALSE); + return (CShellExt::GetRefCount() == 0 ? S_OK : S_FALSE);  }     @@ -145,21 +141,3 @@
 VOID _UnloadResources(VOID)  {  } - - -LPCRITICAL_SECTION CShellExt::GetCriticalSection() -{ - return &g_critical_section; -} - - -void CShellExt::IncDllRef() -{ - ::InterlockedIncrement(&g_cRefThisDll); -} - - -void CShellExt::DecDllRef() -{ - ::InterlockedDecrement(&g_cRefThisDll); -}
 
4
5
6
 
 
 
 
7
8
9
10
 
 
 
 
 
 
11
12
13
 
4
5
6
7
8
9
10
11
 
 
 
12
13
14
15
16
17
18
19
20
@@ -4,10 +4,17 @@
   class CShellExt  { + static CRITICAL_SECTION cs_; + static HMODULE hModule_; + static UINT cRef_; +  public: - static LPCRITICAL_SECTION GetCriticalSection(); - static void IncDllRef(); - static void DecDllRef(); + static LPCRITICAL_SECTION GetCriticalSection() { return &cs_; } + static UINT GetRefCount() { return cRef_; } + static void IncDllRef() { ::InterlockedIncrement(&cRef_); } + static void DecDllRef() { ::InterlockedDecrement(&cRef_); } + + friend BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID);  };