1 // XMergeFactory.cpp: implementation of the CXMergeFactory class. 2 // 3 ////////////////////////////////////////////////////////////////////// 4 5 #include "stdafx.h" 6 7 #include "XMergeFilter.h" 8 #include "XMergeFactory.h" 9 10 ////////////////////////////////////////////////////////////////////// 11 // IUnknown implementation 12 ////////////////////////////////////////////////////////////////////// 13 STDMETHODIMP CXMergeFactory::QueryInterface(REFIID riid, void **ppvObject) 14 { 15 if(ppvObject == NULL) 16 return E_INVALIDARG; 17 18 if(::IsEqualIID(riid, IID_IUnknown) || ::IsEqualIID(riid, IID_IClassFactory)) 19 { 20 *ppvObject = static_cast<IClassFactory*>(this); 21 } 22 else 23 { 24 *ppvObject = NULL; 25 return E_NOINTERFACE; 26 } 27 28 reinterpret_cast<IUnknown*>(*ppvObject)->AddRef(); 29 return S_OK; 30 } 31 32 33 STDMETHODIMP_(ULONG) CXMergeFactory::AddRef() 34 { 35 return ::InterlockedIncrement(&m_cRef); 36 } 37 38 39 STDMETHODIMP_(ULONG) CXMergeFactory::Release() 40 { 41 if(::InterlockedDecrement(&m_cRef) == 0) 42 { 43 delete this; 44 return 0; 45 } 46 47 return m_cRef; 48 } 49 50 51 ////////////////////////////////////////////////////////////////////// 52 // IUnknown implementation 53 ////////////////////////////////////////////////////////////////////// 54 STDMETHODIMP CXMergeFactory::CreateInstance(IUnknown *pUnkOuter, REFIID iid, void **ppvObject) 55 { 56 if (ppvObject == NULL) 57 return E_INVALIDARG; 58 59 if (pUnkOuter != NULL) // cannot aggregate 60 { 61 *ppvObject = NULL; 62 return CLASS_E_NOAGGREGATION; 63 } 64 65 if (iid == IID_ICeFileFilter) 66 { 67 CXMergeFilter *pFilter = new CXMergeFilter(); 68 if(pFilter == NULL) 69 { 70 *ppvObject = NULL; 71 return E_OUTOFMEMORY; 72 } 73 74 HRESULT hr = pFilter->QueryInterface(iid, ppvObject); 75 pFilter->Release(); 76 77 return hr; 78 } 79 80 return E_INVALIDARG; 81 } 82 83 84 STDMETHODIMP CXMergeFactory::LockServer(BOOL fLock) 85 { 86 _Module.LockServer(fLock); 87 return S_OK; 88 } 89 90 91