OSDN Git Service

Merge branch 'rel_0.3.x'
[tortoisegit/TortoiseGitJp.git] / src / TortoiseOverlays / ShellExtClassFactory.cpp
1 // TortoiseOverlays - an overlay handler for Tortoise clients\r
2 // Copyright (C) 2007 - TortoiseSVN\r
3 #include "stdafx.h"\r
4 #include "ShellExt.h"\r
5 #include "ShellExtClassFactory.h"\r
6 \r
7 \r
8 CShellExtClassFactory::CShellExtClassFactory(FileState state)\r
9 {\r
10     m_StateToMake = state;\r
11 \r
12     m_cRef = 0L;\r
13         \r
14     g_cRefThisDll++; \r
15 }\r
16 \r
17 CShellExtClassFactory::~CShellExtClassFactory()          \r
18 {\r
19     g_cRefThisDll--;\r
20 }\r
21 \r
22 STDMETHODIMP CShellExtClassFactory::QueryInterface(REFIID riid,\r
23                                                    LPVOID FAR *ppv)\r
24 {\r
25     *ppv = NULL;\r
26 \r
27     // Any interface on this object is the object pointer\r
28         \r
29     if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))\r
30     {\r
31         *ppv = (LPCLASSFACTORY)this;\r
32                 \r
33         AddRef();\r
34                 \r
35         return NOERROR;\r
36     }\r
37         \r
38     return E_NOINTERFACE;\r
39 }  \r
40 \r
41 STDMETHODIMP_(ULONG) CShellExtClassFactory::AddRef()\r
42 {\r
43     return ++m_cRef;\r
44 }\r
45 \r
46 STDMETHODIMP_(ULONG) CShellExtClassFactory::Release()\r
47 {\r
48     if (--m_cRef)\r
49         return m_cRef;\r
50 \r
51     delete this;\r
52         \r
53     return 0L;\r
54 }\r
55 \r
56 STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,\r
57                                                                                                    REFIID riid,\r
58                                                                                                    LPVOID *ppvObj)\r
59 {\r
60     *ppvObj = NULL;\r
61         \r
62     // Shell extensions typically don't support aggregation (inheritance)\r
63         \r
64     if (pUnkOuter)\r
65         return CLASS_E_NOAGGREGATION;\r
66         \r
67     // Create the main shell extension object.  The shell will then call\r
68     // QueryInterface with IID_IShellExtInit--this is how shell extensions are\r
69     // initialized.\r
70         \r
71     CShellExt* pShellExt = new CShellExt(m_StateToMake);  //Create the CShellExt object\r
72                 \r
73     if (NULL == pShellExt)\r
74         return E_OUTOFMEMORY;\r
75         \r
76     return pShellExt->QueryInterface(riid, ppvObj);\r
77 }\r
78 \r
79 \r
80 STDMETHODIMP CShellExtClassFactory::LockServer(BOOL /*fLock*/)\r
81 {\r
82     return E_NOTIMPL;\r
83 }\r