Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / TortoiseShell / ShellExtClassFactory.cpp
blob0999795ba82d684ebd0fdc8e861fc4b0d003fb40
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2009-2011 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "ShellExt.h"
21 #include "ShellExtClassFactory.h"
24 CShellExtClassFactory::CShellExtClassFactory(FileState state)
25 : m_StateToMake(state)
26 , m_cRef(0L)
28 InterlockedIncrement(&g_cRefThisDll);
31 CShellExtClassFactory::~CShellExtClassFactory()
33 InterlockedDecrement(&g_cRefThisDll);
36 STDMETHODIMP CShellExtClassFactory::QueryInterface(REFIID riid,
37 LPVOID FAR *ppv)
39 if (!ppv)
40 return E_POINTER;
42 *ppv = nullptr;
44 // Any interface on this object is the object pointer
46 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
48 *ppv = static_cast<LPCLASSFACTORY>(this);
49 AddRef();
50 return S_OK;
53 return E_NOINTERFACE;
56 STDMETHODIMP_(ULONG) CShellExtClassFactory::AddRef()
58 git_libgit2_init();
59 return InterlockedIncrement(&m_cRef);
62 STDMETHODIMP_(ULONG) CShellExtClassFactory::Release()
64 if (InterlockedDecrement(&m_cRef))
65 return m_cRef;
67 delete this;
69 git_libgit2_shutdown();
71 return 0L;
74 STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,
75 REFIID riid,
76 LPVOID *ppvObj)
78 if (!ppvObj)
79 return E_POINTER;
81 *ppvObj = nullptr;
83 // Shell extensions typically don't support aggregation (inheritance)
85 if (pUnkOuter)
86 return CLASS_E_NOAGGREGATION;
88 // Create the main shell extension object. The shell will then call
89 // QueryInterface with IID_IShellExtInit--this is how shell extensions are
90 // initialized.
92 CShellExt* pShellExt = new (std::nothrow) CShellExt(m_StateToMake); //Create the CShellExt object
94 if (!pShellExt)
95 return E_OUTOFMEMORY;
97 const HRESULT hr = pShellExt->QueryInterface(riid, ppvObj);
98 if(FAILED(hr))
99 delete pShellExt;
100 return hr;
103 STDMETHODIMP CShellExtClassFactory::LockServer(BOOL /*fLock*/)
105 return E_NOTIMPL;