1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * COPYRIGHT: See COPYING in the top level directory
3*c2c66affSColin Finck * PROJECT: ReactOS Configuration of network devices
4*c2c66affSColin Finck * FILE: dll/directx/dsound_new/classfactory.c
5*c2c66affSColin Finck * PURPOSE: IClassFactory implementation
6*c2c66affSColin Finck *
7*c2c66affSColin Finck * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8*c2c66affSColin Finck */
9*c2c66affSColin Finck
10*c2c66affSColin Finck
11*c2c66affSColin Finck #include "precomp.h"
12*c2c66affSColin Finck
13*c2c66affSColin Finck typedef struct
14*c2c66affSColin Finck {
15*c2c66affSColin Finck const IClassFactoryVtbl *lpVtbl;
16*c2c66affSColin Finck LONG ref;
17*c2c66affSColin Finck CLSID *rclsid;
18*c2c66affSColin Finck LPFNCREATEINSTANCE lpfnCI;
19*c2c66affSColin Finck const IID * riidInst;
20*c2c66affSColin Finck } IClassFactoryImpl;
21*c2c66affSColin Finck
22*c2c66affSColin Finck
23*c2c66affSColin Finck static
24*c2c66affSColin Finck HRESULT
25*c2c66affSColin Finck WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID * ppvObj)26*c2c66affSColin Finck IClassFactory_fnQueryInterface(
27*c2c66affSColin Finck LPCLASSFACTORY iface,
28*c2c66affSColin Finck REFIID riid,
29*c2c66affSColin Finck LPVOID *ppvObj)
30*c2c66affSColin Finck {
31*c2c66affSColin Finck IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
32*c2c66affSColin Finck
33*c2c66affSColin Finck *ppvObj = NULL;
34*c2c66affSColin Finck
35*c2c66affSColin Finck /* check requested interface */
36*c2c66affSColin Finck if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
37*c2c66affSColin Finck {
38*c2c66affSColin Finck *ppvObj = This;
39*c2c66affSColin Finck InterlockedIncrement(&This->ref);
40*c2c66affSColin Finck return S_OK;
41*c2c66affSColin Finck }
42*c2c66affSColin Finck return E_NOINTERFACE;
43*c2c66affSColin Finck }
44*c2c66affSColin Finck
45*c2c66affSColin Finck static
46*c2c66affSColin Finck ULONG
47*c2c66affSColin Finck WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface)48*c2c66affSColin Finck IClassFactory_fnAddRef(
49*c2c66affSColin Finck LPCLASSFACTORY iface)
50*c2c66affSColin Finck {
51*c2c66affSColin Finck IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
52*c2c66affSColin Finck
53*c2c66affSColin Finck /* increment reference count */
54*c2c66affSColin Finck ULONG refCount = InterlockedIncrement(&This->ref);
55*c2c66affSColin Finck
56*c2c66affSColin Finck return refCount;
57*c2c66affSColin Finck }
58*c2c66affSColin Finck
59*c2c66affSColin Finck static
60*c2c66affSColin Finck ULONG
61*c2c66affSColin Finck WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface)62*c2c66affSColin Finck IClassFactory_fnRelease(
63*c2c66affSColin Finck LPCLASSFACTORY iface)
64*c2c66affSColin Finck {
65*c2c66affSColin Finck IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
66*c2c66affSColin Finck ULONG refCount = InterlockedDecrement(&This->ref);
67*c2c66affSColin Finck
68*c2c66affSColin Finck /* decrement reference count */
69*c2c66affSColin Finck if (!refCount)
70*c2c66affSColin Finck {
71*c2c66affSColin Finck /* free class factory */
72*c2c66affSColin Finck CoTaskMemFree(This);
73*c2c66affSColin Finck return 0;
74*c2c66affSColin Finck }
75*c2c66affSColin Finck return refCount;
76*c2c66affSColin Finck }
77*c2c66affSColin Finck
78*c2c66affSColin Finck static
79*c2c66affSColin Finck HRESULT
80*c2c66affSColin Finck WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pUnkOuter,REFIID riid,LPVOID * ppvObject)81*c2c66affSColin Finck IClassFactory_fnCreateInstance(
82*c2c66affSColin Finck LPCLASSFACTORY iface,
83*c2c66affSColin Finck LPUNKNOWN pUnkOuter,
84*c2c66affSColin Finck REFIID riid,
85*c2c66affSColin Finck LPVOID *ppvObject)
86*c2c66affSColin Finck {
87*c2c66affSColin Finck IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
88*c2c66affSColin Finck
89*c2c66affSColin Finck if (!ppvObject)
90*c2c66affSColin Finck return E_INVALIDARG;
91*c2c66affSColin Finck
92*c2c66affSColin Finck *ppvObject = NULL;
93*c2c66affSColin Finck
94*c2c66affSColin Finck if ( This->riidInst==NULL || IsEqualCLSID(riid, This->riidInst) || IsEqualCLSID(riid, &IID_IUnknown) )
95*c2c66affSColin Finck {
96*c2c66affSColin Finck /* instantiate object */
97*c2c66affSColin Finck return This->lpfnCI(pUnkOuter, riid, ppvObject);
98*c2c66affSColin Finck }
99*c2c66affSColin Finck
100*c2c66affSColin Finck return E_NOINTERFACE;
101*c2c66affSColin Finck }
102*c2c66affSColin Finck
103*c2c66affSColin Finck static
104*c2c66affSColin Finck HRESULT
IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL fLock)105*c2c66affSColin Finck WINAPI IClassFactory_fnLockServer(
106*c2c66affSColin Finck LPCLASSFACTORY iface,
107*c2c66affSColin Finck BOOL fLock)
108*c2c66affSColin Finck {
109*c2c66affSColin Finck //IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
110*c2c66affSColin Finck return E_NOTIMPL;
111*c2c66affSColin Finck }
112*c2c66affSColin Finck
113*c2c66affSColin Finck
114*c2c66affSColin Finck static const IClassFactoryVtbl dclfvt =
115*c2c66affSColin Finck {
116*c2c66affSColin Finck IClassFactory_fnQueryInterface,
117*c2c66affSColin Finck IClassFactory_fnAddRef,
118*c2c66affSColin Finck IClassFactory_fnRelease,
119*c2c66affSColin Finck IClassFactory_fnCreateInstance,
120*c2c66affSColin Finck IClassFactory_fnLockServer
121*c2c66affSColin Finck };
122*c2c66affSColin Finck
123*c2c66affSColin Finck
124*c2c66affSColin Finck IClassFactory *
IClassFactory_fnConstructor(LPFNCREATEINSTANCE lpfnCI,PLONG pcRefDll,REFIID riidInst)125*c2c66affSColin Finck IClassFactory_fnConstructor(
126*c2c66affSColin Finck LPFNCREATEINSTANCE lpfnCI,
127*c2c66affSColin Finck PLONG pcRefDll,
128*c2c66affSColin Finck REFIID riidInst)
129*c2c66affSColin Finck {
130*c2c66affSColin Finck IClassFactoryImpl* lpclf;
131*c2c66affSColin Finck
132*c2c66affSColin Finck lpclf = CoTaskMemAlloc(sizeof(IClassFactoryImpl));
133*c2c66affSColin Finck lpclf->ref = 1;
134*c2c66affSColin Finck lpclf->lpVtbl = &dclfvt;
135*c2c66affSColin Finck lpclf->lpfnCI = lpfnCI;
136*c2c66affSColin Finck
137*c2c66affSColin Finck if (pcRefDll)
138*c2c66affSColin Finck InterlockedIncrement(pcRefDll);
139*c2c66affSColin Finck lpclf->riidInst = riidInst;
140*c2c66affSColin Finck
141*c2c66affSColin Finck return (LPCLASSFACTORY)lpclf;
142*c2c66affSColin Finck }
143*c2c66affSColin Finck
144*c2c66affSColin Finck
145