Merge branch 'master' of git://github.com/Jopie64/tortoisegit
[TortoiseGit.git] / src / TortoiseOverlays / ShellExt.cpp
blob6f637de2369b170a550c6aad38153eaecbd59961
1 // TortoiseOverlays - an overlay handler for Tortoise clients
2 // Copyright (C) 2007 - TortoiseSVN
3 #include "stdafx.h"
5 #pragma warning (disable : 4786)
7 // Initialize GUIDs (should be done only and at-least once per DLL/EXE)
8 #include <initguid.h>
9 #include "Guids.h"
11 #include "ShellExt.h"
14 // *********************** CShellExt *************************
15 CShellExt::CShellExt(FileState state)
17 m_State = state;
19 m_cRef = 0L;
20 g_cRefThisDll++;
24 CShellExt::~CShellExt()
26 g_cRefThisDll--;
30 STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)
32 *ppv = NULL;
34 if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))
36 *ppv = (LPSHELLEXTINIT)this;
38 else if (IsEqualIID(riid, IID_IContextMenu))
40 *ppv = (LPCONTEXTMENU)this;
42 else if (IsEqualIID(riid, IID_IContextMenu2))
44 *ppv = (LPCONTEXTMENU2)this;
46 else if (IsEqualIID(riid, IID_IContextMenu3))
48 *ppv = (LPCONTEXTMENU3)this;
50 else if (IsEqualIID(riid, IID_IShellIconOverlayIdentifier))
52 *ppv = (IShellIconOverlayIdentifier*)this;
54 else if (IsEqualIID(riid, IID_IShellPropSheetExt))
56 *ppv = (LPSHELLPROPSHEETEXT)this;
58 if (*ppv)
60 AddRef();
62 return NOERROR;
65 return E_NOINTERFACE;
68 STDMETHODIMP_(ULONG) CShellExt::AddRef()
70 return ++m_cRef;
73 STDMETHODIMP_(ULONG) CShellExt::Release()
75 if (--m_cRef)
76 return m_cRef;
78 for (vector<DLLPointers>::iterator it = m_dllpointers.begin(); it != m_dllpointers.end(); ++it)
80 if (it->pShellIconOverlayIdentifier != NULL)
81 it->pShellIconOverlayIdentifier->Release();
82 if (it->hDll != NULL)
83 FreeLibrary(it->hDll);
85 it->hDll = NULL;
86 it->pDllGetClassObject = NULL;
87 it->pDllCanUnloadNow = NULL;
88 it->pShellIconOverlayIdentifier = NULL;
91 m_dllpointers.clear();
93 delete this;
95 return 0L;