Index: src/chext/ClassFactory.cpp =================================================================== diff -u -r6609ba39811176f4803f0556db3da30e9e457b9d -r86528d792f82b7ceb7b0fe34345bf66a9656d538 --- src/chext/ClassFactory.cpp (.../ClassFactory.cpp) (revision 6609ba39811176f4803f0556db3da30e9e457b9d) +++ src/chext/ClassFactory.cpp (.../ClassFactory.cpp) (revision 86528d792f82b7ceb7b0fe34345bf66a9656d538) @@ -20,18 +20,18 @@ #include "ClassFactory.h" #include "Logger.h" -extern LONG g_DllRefCount; +extern std::atomic g_DllRefCount; ClassFactory::ClassFactory() : m_spLog(GetLogger(L"ClassFactory")) { - InterlockedIncrement(&g_DllRefCount); + ++g_DllRefCount; LOG_DEBUG(m_spLog) << L"Constructing ClassFactory"; } ClassFactory::~ClassFactory() { - InterlockedDecrement(&g_DllRefCount); + --g_DllRefCount; } STDMETHODIMP ClassFactory::QueryInterface(REFIID riid, LPVOID *ppReturn) Index: src/chext/DropMenuExt.cpp =================================================================== diff -u -r6609ba39811176f4803f0556db3da30e9e457b9d -r86528d792f82b7ceb7b0fe34345bf66a9656d538 --- src/chext/DropMenuExt.cpp (.../DropMenuExt.cpp) (revision 6609ba39811176f4803f0556db3da30e9e457b9d) +++ src/chext/DropMenuExt.cpp (.../DropMenuExt.cpp) (revision 86528d792f82b7ceb7b0fe34345bf66a9656d538) @@ -26,13 +26,17 @@ #include "ShellExtensionVerifier.h" #include "HResultFormatter.h" +extern std::atomic g_DllRefCount; + ///////////////////////////////////////////////////////////////////////////// // CDropMenuExt CDropMenuExt::CDropMenuExt() : m_piShellExtControl(nullptr), m_spLog(GetLogger(L"CDropMenuExt")) { + ++g_DllRefCount; + HRESULT hResult = CoCreateInstance(CLSID_CShellExtControl, nullptr, CLSCTX_ALL, IID_IShellExtControl, (void**)&m_piShellExtControl); LOG_HRESULT(m_spLog, hResult) << L"Create instance of ShellExtControl"; @@ -45,6 +49,8 @@ m_piShellExtControl->Release(); m_piShellExtControl = nullptr; } + + --g_DllRefCount; } STDMETHODIMP CDropMenuExt::QueryInterface(REFIID riid, LPVOID FAR *ppvObject) Index: src/chext/MenuExt.cpp =================================================================== diff -u -r6609ba39811176f4803f0556db3da30e9e457b9d -r86528d792f82b7ceb7b0fe34345bf66a9656d538 --- src/chext/MenuExt.cpp (.../MenuExt.cpp) (revision 6609ba39811176f4803f0556db3da30e9e457b9d) +++ src/chext/MenuExt.cpp (.../MenuExt.cpp) (revision 86528d792f82b7ceb7b0fe34345bf66a9656d538) @@ -29,12 +29,16 @@ #include "Logger.h" #include "../libchengine/TTaskDefinition.h" +extern std::atomic g_DllRefCount; + ///////////////////////////////////////////////////////////////////////////// // CMenuExt CMenuExt::CMenuExt() : m_piShellExtControl(nullptr), m_spLog(GetLogger(L"CMenuExt")) { + ++g_DllRefCount; + HRESULT hResult = CoCreateInstance(CLSID_CShellExtControl, nullptr, CLSCTX_ALL, IID_IShellExtControl, (void**)&m_piShellExtControl); LOG_HRESULT(m_spLog, hResult) << L"Creation of ShellExtControl " << LOG_PARAM(m_piShellExtControl); } @@ -46,6 +50,8 @@ m_piShellExtControl->Release(); m_piShellExtControl = nullptr; } + + --g_DllRefCount; } STDMETHODIMP CMenuExt::QueryInterface(REFIID riid, LPVOID FAR *ppvObject) Index: src/chext/ShellExtControl.cpp =================================================================== diff -u -r6609ba39811176f4803f0556db3da30e9e457b9d -r86528d792f82b7ceb7b0fe34345bf66a9656d538 --- src/chext/ShellExtControl.cpp (.../ShellExtControl.cpp) (revision 6609ba39811176f4803f0556db3da30e9e457b9d) +++ src/chext/ShellExtControl.cpp (.../ShellExtControl.cpp) (revision 86528d792f82b7ceb7b0fe34345bf66a9656d538) @@ -23,10 +23,13 @@ #include "Logger.h" #include "../libchcore/TIpcMutexLock.h" +extern std::atomic g_DllRefCount; + CShellExtControl::CShellExtControl() : m_mutex(L"CHShellExtControlDataMutex"), m_spLog(GetLogger(L"ShellExtControl")) { + ++g_DllRefCount; LOG_DEBUG(m_spLog) << L"Constructing CShellExtControl"; } @@ -37,8 +40,10 @@ UnmapViewOfFile((LPVOID)m_pShellExtData); // Close the process's handle to the file-mapping object. - CloseHandle(m_hMemory); + CloseHandle(m_hMemory); } + + --g_DllRefCount; } STDMETHODIMP CShellExtControl::QueryInterface(REFIID riid, LPVOID FAR *ppvObject) Index: src/chext/chext.cpp =================================================================== diff -u -r6609ba39811176f4803f0556db3da30e9e457b9d -r86528d792f82b7ceb7b0fe34345bf66a9656d538 --- src/chext/chext.cpp (.../chext.cpp) (revision 6609ba39811176f4803f0556db3da30e9e457b9d) +++ src/chext/chext.cpp (.../chext.cpp) (revision 86528d792f82b7ceb7b0fe34345bf66a9656d538) @@ -25,7 +25,8 @@ #include "../common/TRegistry.h" #include "DllRegistration.h" -LONG g_DllRefCount = 0; // Reference count of this DLL. +std::atomic g_DllRefCount = 0; + extern HINSTANCE g_hInstance; namespace