OSDN Git Service

Merge branch 'rel_0.3.x'
[tortoisegit/TortoiseGitJp.git] / src / TortoiseOverlays / ShellExt.cpp
1 // TortoiseOverlays - an overlay handler for Tortoise clients\r
2 // Copyright (C) 2007 - TortoiseSVN\r
3 #include "stdafx.h"\r
4 \r
5 #pragma warning (disable : 4786)\r
6 \r
7 // Initialize GUIDs (should be done only and at-least once per DLL/EXE)\r
8 #include <initguid.h>\r
9 #include "Guids.h"\r
10 \r
11 #include "ShellExt.h"\r
12 \r
13 \r
14 // *********************** CShellExt *************************\r
15 CShellExt::CShellExt(FileState state)\r
16 {\r
17     m_State = state;\r
18 \r
19     m_cRef = 0L;\r
20     g_cRefThisDll++;\r
21         \r
22 }\r
23 \r
24 CShellExt::~CShellExt()\r
25 {\r
26         g_cRefThisDll--;\r
27 }\r
28 \r
29 \r
30 STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)\r
31 {\r
32     *ppv = NULL; \r
33 \r
34     if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))\r
35     {\r
36         *ppv = (LPSHELLEXTINIT)this;\r
37     }\r
38     else if (IsEqualIID(riid, IID_IContextMenu))\r
39     {\r
40         *ppv = (LPCONTEXTMENU)this;\r
41     }\r
42     else if (IsEqualIID(riid, IID_IContextMenu2))\r
43     {\r
44         *ppv = (LPCONTEXTMENU2)this;\r
45     }\r
46     else if (IsEqualIID(riid, IID_IContextMenu3))\r
47     {\r
48         *ppv = (LPCONTEXTMENU3)this;\r
49     }\r
50     else if (IsEqualIID(riid, IID_IShellIconOverlayIdentifier))\r
51     {\r
52         *ppv = (IShellIconOverlayIdentifier*)this;\r
53     }\r
54     else if (IsEqualIID(riid, IID_IShellPropSheetExt))\r
55     {\r
56         *ppv = (LPSHELLPROPSHEETEXT)this;\r
57     }\r
58     if (*ppv)\r
59     {\r
60         AddRef();\r
61                 \r
62         return NOERROR;\r
63     }\r
64         \r
65     return E_NOINTERFACE;\r
66 }\r
67 \r
68 STDMETHODIMP_(ULONG) CShellExt::AddRef()\r
69 {\r
70     return ++m_cRef;\r
71 }\r
72 \r
73 STDMETHODIMP_(ULONG) CShellExt::Release()\r
74 {\r
75     if (--m_cRef)\r
76         return m_cRef;\r
77 \r
78         for (vector<DLLPointers>::iterator it = m_dllpointers.begin(); it != m_dllpointers.end(); ++it)\r
79         {\r
80                 if (it->pShellIconOverlayIdentifier != NULL)\r
81                         it->pShellIconOverlayIdentifier->Release();\r
82                 if (it->hDll != NULL)\r
83                         FreeLibrary(it->hDll);\r
84 \r
85                 it->hDll = NULL;\r
86                 it->pDllGetClassObject = NULL;\r
87                 it->pDllCanUnloadNow = NULL;\r
88                 it->pShellIconOverlayIdentifier = NULL;\r
89         }\r
90 \r
91         m_dllpointers.clear();\r
92 \r
93     delete this;\r
94         \r
95     return 0L;\r
96 }\r
97 \r
98 \r