Commits

Anonymous committed eada6f0

shellext: clean up code

Comments (0)

Files changed (2)

win32/shellext/ShellExt.cpp

 #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
 {
 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();
     }
 
 STDAPI DllCanUnloadNow(void)
 {
     TDEBUG_TRACE("DllCanUnloadNow");
-    return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
+    return (CShellExt::GetRefCount() == 0 ? S_OK : S_FALSE);
 }
 
 
 VOID _UnloadResources(VOID)
 {
 }
-
-
-LPCRITICAL_SECTION CShellExt::GetCriticalSection()
-{
-    return &g_critical_section;
-}
-
-
-void CShellExt::IncDllRef()
-{
-    ::InterlockedIncrement(&g_cRefThisDll);
-}
-
-
-void CShellExt::DecDllRef()
-{
-    ::InterlockedDecrement(&g_cRefThisDll);
-}

win32/shellext/ShellExt.h

 
 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);
 };