1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 // XMergeFactory.cpp: implementation of the CXMergeFactory class.
23 //
24 //////////////////////////////////////////////////////////////////////
25
26 #include "stdafx.h"
27
28 #include "XMergeFilter.h"
29 #include "XMergeFactory.h"
30
31 //////////////////////////////////////////////////////////////////////
32 // IUnknown implementation
33 //////////////////////////////////////////////////////////////////////
QueryInterface(REFIID riid,void ** ppvObject)34 STDMETHODIMP CXMergeFactory::QueryInterface(REFIID riid, void **ppvObject)
35 {
36 if(ppvObject == NULL)
37 return E_INVALIDARG;
38
39 if(::IsEqualIID(riid, IID_IUnknown) || ::IsEqualIID(riid, IID_IClassFactory))
40 {
41 *ppvObject = static_cast<IClassFactory*>(this);
42 }
43 else
44 {
45 *ppvObject = NULL;
46 return E_NOINTERFACE;
47 }
48
49 reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
50 return S_OK;
51 }
52
53
STDMETHODIMP_(ULONG)54 STDMETHODIMP_(ULONG) CXMergeFactory::AddRef()
55 {
56 return ::InterlockedIncrement(&m_cRef);
57 }
58
59
STDMETHODIMP_(ULONG)60 STDMETHODIMP_(ULONG) CXMergeFactory::Release()
61 {
62 if(::InterlockedDecrement(&m_cRef) == 0)
63 {
64 delete this;
65 return 0;
66 }
67
68 return m_cRef;
69 }
70
71
72 //////////////////////////////////////////////////////////////////////
73 // IUnknown implementation
74 //////////////////////////////////////////////////////////////////////
CreateInstance(IUnknown * pUnkOuter,REFIID iid,void ** ppvObject)75 STDMETHODIMP CXMergeFactory::CreateInstance(IUnknown *pUnkOuter, REFIID iid, void **ppvObject)
76 {
77 if (ppvObject == NULL)
78 return E_INVALIDARG;
79
80 if (pUnkOuter != NULL) // cannot aggregate
81 {
82 *ppvObject = NULL;
83 return CLASS_E_NOAGGREGATION;
84 }
85
86 if (iid == IID_ICeFileFilter)
87 {
88 CXMergeFilter *pFilter = new CXMergeFilter();
89 if(pFilter == NULL)
90 {
91 *ppvObject = NULL;
92 return E_OUTOFMEMORY;
93 }
94
95 HRESULT hr = pFilter->QueryInterface(iid, ppvObject);
96 pFilter->Release();
97
98 return hr;
99 }
100
101 return E_INVALIDARG;
102 }
103
104
LockServer(BOOL fLock)105 STDMETHODIMP CXMergeFactory::LockServer(BOOL fLock)
106 {
107 _Module.LockServer(fLock);
108 return S_OK;
109 }
110
111
112