Changeset 58bbddf1abaf…
Parent ea4ecbdd8d41…
by
Changes to 7 files · Browse files at 58bbddf1abaf Showing diff from parent ea4ecbdd8d41 Diff from another changeset...
@@ -973,8 +973,11 @@
CShellExtCMenu::CShellExtCMenu(const char dummy)
{
- m_cRef = 0L;
- CShellExt::IncDllRef();
+ CShellExt::IncDllRef();
+ ADDIFACE(IShellExtInit);
+ ADDIFACE(IContextMenu);
+ ADDIFACE(IContextMenu2);
+ ADDIFACE(IContextMenu3);
}
@@ -983,51 +986,4 @@ CShellExt::DecDllRef();
}
-
-STDMETHODIMP_(ULONG) CShellExtCMenu::AddRef()
-{
- return ::InterlockedIncrement(&m_cRef);
-}
-
-
-STDMETHODIMP_(ULONG) CShellExtCMenu::Release()
-{
- if(::InterlockedDecrement(&m_cRef))
- return m_cRef;
- delete this;
- return 0L;
-}
-
-
-STDMETHODIMP CShellExtCMenu::QueryInterface(REFIID riid, LPVOID FAR* ppv)
-{
- if (ppv == 0)
- return E_POINTER;
-
- *ppv = NULL;
-
- if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))
- {
- *ppv = (LPSHELLEXTINIT) this;
- }
- else if (IsEqualIID(riid, IID_IContextMenu))
- {
- *ppv = (LPCONTEXTMENU) this;
- }
- else if (IsEqualIID(riid, IID_IContextMenu2))
- {
- *ppv = (IContextMenu2*) this;
- }
- else if (IsEqualIID(riid, IID_IContextMenu3))
- {
- *ppv = (IContextMenu3*) this;
- }
-
- if (*ppv)
- {
- AddRef();
- return S_OK;
- }
-
- return E_NOINTERFACE;
-}
+IMPLEMENT_UNKNOWN(CShellExtCMenu)
|
@@ -5,6 +5,8 @@ #include <string>
#include <map>
+#include "SimpleUnknown.h"
+
struct MenuDescription
{
std::string name;
@@ -19,7 +21,7 @@typedef std::map<UINT, MenuDescription> MenuIdCmdMap;
-class CShellExtCMenu: public IContextMenu3, IShellExtInit
+class CShellExtCMenu: public CSimpleUnknown, IContextMenu3, IShellExtInit
{
protected:
@@ -43,10 +45,7 @@ explicit CShellExtCMenu(const char dummy);
~CShellExtCMenu();
- // IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR *ppv);
- STDMETHODIMP_(ULONG) AddRef();
- STDMETHODIMP_(ULONG) Release();
+ DECLARE_UNKNOWN()
// IContextMenu3
STDMETHODIMP QueryContextMenu(
|
@@ -77,8 +77,8 @@ CShellExtOverlay::CShellExtOverlay(char tortoiseClass) :
myTortoiseClass(tortoiseClass)
{
- m_cRef = 0L;
CShellExt::IncDllRef();
+ ADDIFACE(IShellIconOverlayIdentifier);
}
@@ -87,40 +87,4 @@ CShellExt::DecDllRef();
}
-
-STDMETHODIMP_(ULONG) CShellExtOverlay::AddRef()
-{
- return ::InterlockedIncrement(&m_cRef);
-}
-
-
-STDMETHODIMP_(ULONG) CShellExtOverlay::Release()
-{
- if(::InterlockedDecrement(&m_cRef))
- return m_cRef;
- delete this;
- return 0L;
-}
-
-
-STDMETHODIMP CShellExtOverlay::QueryInterface(REFIID riid, LPVOID FAR* ppv)
-{
- if (ppv == 0)
- return E_POINTER;
-
- *ppv = NULL;
-
- if (IsEqualIID(riid, IID_IShellIconOverlayIdentifier)
- || IsEqualIID(riid, IID_IUnknown) )
- {
- *ppv = (IShellIconOverlayIdentifier*) this;
- }
-
- if (*ppv)
- {
- AddRef();
- return S_OK;
- }
-
- return E_NOINTERFACE;
-}
+IMPLEMENT_UNKNOWN(CShellExtOverlay)
\ No newline at end of file |
@@ -1,20 +1,17 @@ #ifndef _CShellExtOverlay_h_
#define _CShellExtOverlay_h_
+#include "SimpleUnknown.h"
-class CShellExtOverlay: public IShellIconOverlayIdentifier
+class CShellExtOverlay: public CSimpleUnknown, public IShellIconOverlayIdentifier
{
- ULONG m_cRef;
const char myTortoiseClass;
public:
explicit CShellExtOverlay(char Class);
~CShellExtOverlay();
- // IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR *ppv);
- STDMETHODIMP_(ULONG) AddRef();
- STDMETHODIMP_(ULONG) Release();
+ DECLARE_UNKNOWN()
// IShellIconOverlayIdentifier
STDMETHODIMP GetOverlayInfo(
|
@@ -22,7 +22,8 @@ DirectoryStatus.obj \
Thgstatus.obj \
QueryDirstate.obj \
- ThgVersion.obj
+ ThgVersion.obj \
+ SimpleUnknown.obj
OBJECTS_TERMINATE = Thgstatus.obj \
RegistryConfig.obj \
|
|
@@ -0,0 +1,76 @@ + // Copyright (C) 2011 Fog Creek Software
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "stdafx.h"
+
+#include "SimpleUnknown.h"
+
+CSimpleUnknown::CSimpleUnknown()
+{
+ entries_ = NULL;
+ cRef_ = 0;
+ AddInterface(IID_IUnknown, this);
+}
+
+CSimpleUnknown::~CSimpleUnknown()
+{
+ Entry* entry = entries_;
+ while (entry != NULL)
+ {
+ Entry* nextentry = entry->next;
+ delete entry;
+ entry = nextentry;
+ }
+}
+
+void CSimpleUnknown::AddInterface(REFIID riid, LPUNKNOWN punk)
+{
+ Entry* newentry = new Entry;
+ newentry->iid = riid;
+ newentry->punk = punk;
+ newentry->next = entries_;
+ entries_ = newentry;
+}
+
+STDMETHODIMP CSimpleUnknown::QueryInterface(REFIID riid, LPVOID FAR* ppv)
+{
+ if (ppv == NULL)
+ return E_POINTER;
+
+ for (Entry* entry = entries_; entry != NULL; entry = entry->next)
+ {
+ if (entry->iid == riid)
+ {
+ entry->punk->AddRef();
+ *ppv = entry->punk;
+ return S_OK;
+ }
+ }
+ *ppv = NULL;
+ return E_NOINTERFACE;
+}
+
+STDMETHODIMP_(ULONG) CSimpleUnknown::AddRef()
+{
+ return ::InterlockedIncrement(&cRef_);
+}
+
+STDMETHODIMP_(ULONG) CSimpleUnknown::Release()
+{
+ if (::InterlockedDecrement(&cRef_))
+ return cRef_;
+ delete this;
+ return 0L;
+}
|
|
@@ -0,0 +1,62 @@ + // Copyright (C) 2011 Fog Creek Software
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef _SIMPLEUNKNOWN_H_
+#define _SIMPLEUNKNOWN_H_
+
+#define DECLARE_UNKNOWN() \
+ STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR* ppv); \
+ STDMETHOD_(ULONG, AddRef)(); \
+ STDMETHOD_(ULONG, Release)(); \
+
+#define IMPLEMENT_UNKNOWN(classname) \
+ STDMETHODIMP classname::QueryInterface(REFIID riid, LPVOID FAR* ppv) \
+ { \
+ return CSimpleUnknown::QueryInterface(riid, ppv); \
+ } \
+ STDMETHODIMP_(ULONG) classname::AddRef() \
+ { \
+ return CSimpleUnknown::AddRef(); \
+ } \
+ STDMETHODIMP_(ULONG) classname::Release() \
+ { \
+ return CSimpleUnknown::Release(); \
+ }
+
+#define ADDIFACE(iface) \
+ AddInterface(IID_##iface, (iface*)this)
+
+class CSimpleUnknown : public IUnknown
+{
+ struct Entry
+ {
+ IID iid;
+ LPUNKNOWN punk;
+ Entry* next;
+ };
+ Entry* entries_;
+ UINT cRef_;
+
+protected:
+ void AddInterface(REFIID riid, IUnknown* punk);
+
+public:
+ CSimpleUnknown();
+ virtual ~CSimpleUnknown();
+
+ DECLARE_UNKNOWN()
+};
+
+#endif
|
Loading...