1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS WDM Streaming ActiveMovie Proxy
4  * FILE:            dll/directx/ksproxy/classfactory.cpp
5  * PURPOSE:         IClassFactory interface
6  *
7  * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 #include "precomp.h"
10 
11 class CClassFactory : public IClassFactory
12 {
13 public:
14     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
15 
16     STDMETHODIMP_(ULONG) AddRef()
17     {
18         InterlockedIncrement(&m_Ref);
19         return m_Ref;
20     }
21     STDMETHODIMP_(ULONG) Release()
22     {
23         InterlockedDecrement(&m_Ref);
24 
25         if (!m_Ref)
26         {
27             delete this;
28             return 0;
29         }
30         return m_Ref;
31     }
32 
33     HRESULT WINAPI CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject);
34     HRESULT WINAPI LockServer(BOOL fLock);
35 
36     CClassFactory(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, IID *riidInst) : m_Ref(1), m_lpfnCI(lpfnCI), m_IID(riidInst)
37     {};
38 
39     virtual ~CClassFactory(){};
40 
41 protected:
42     LONG m_Ref;
43     LPFNCREATEINSTANCE m_lpfnCI;
44     IID * m_IID;
45 };
46 
47 HRESULT
48 WINAPI
49 CClassFactory::QueryInterface(
50     REFIID riid,
51     LPVOID *ppvObj)
52 {
53     *ppvObj = NULL;
54     if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
55     {
56         *ppvObj = PVOID(this);
57         InterlockedIncrement(&m_Ref);
58         return S_OK;
59     }
60     return E_NOINTERFACE;
61 }
62 
63 HRESULT
64 WINAPI
65 CClassFactory::CreateInstance(
66     LPUNKNOWN pUnkOuter,
67     REFIID riid,
68     LPVOID *ppvObject)
69 {
70     WCHAR Buffer[MAX_PATH];
71     LPOLESTR lpstr;
72 
73     *ppvObject = NULL;
74 
75     StringFromCLSID(riid, &lpstr);
76 
77     swprintf(Buffer, L"riid %s", lpstr);
78     OutputDebugStringW(Buffer);
79 
80 
81     if ( m_IID == NULL || IsEqualCLSID(riid, *m_IID) || IsEqualCLSID(riid, IID_IUnknown))
82     {
83         return m_lpfnCI(pUnkOuter, riid, ppvObject);
84     }
85 
86     return E_NOINTERFACE;
87 }
88 
89 HRESULT
90 WINAPI
91 CClassFactory::LockServer(
92     BOOL fLock)
93 {
94     return E_NOTIMPL;
95 }
96 
97 IClassFactory *
98 CClassFactory_fnConstructor(
99     LPFNCREATEINSTANCE lpfnCI,
100     PLONG pcRefDll,
101     IID * riidInst)
102 {
103     CClassFactory* factory = new CClassFactory(lpfnCI, pcRefDll, riidInst);
104 
105     if (!factory)
106         return NULL;
107 
108     if (pcRefDll)
109         InterlockedIncrement(pcRefDll);
110 
111     return (LPCLASSFACTORY)factory;
112 }
113