1 #include "precomp.h"
2
3 typedef struct
4 {
5 const IClassFactoryVtbl *lpVtbl;
6 LONG ref;
7 CLSID *rclsid;
8 LPFNCREATEINSTANCE lpfnCI;
9 const IID * riidInst;
10 } IClassFactoryImpl;
11
12
13 static
14 HRESULT
15 WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID * ppvObj)16 IClassFactory_fnQueryInterface(
17 LPCLASSFACTORY iface,
18 REFIID riid,
19 LPVOID *ppvObj)
20 {
21 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
22
23 *ppvObj = NULL;
24 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
25 {
26 *ppvObj = This;
27 InterlockedIncrement(&This->ref);
28 return S_OK;
29 }
30 return E_NOINTERFACE;
31 }
32
33 static
34 ULONG
35 WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface)36 IClassFactory_fnAddRef(
37 LPCLASSFACTORY iface)
38 {
39 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
40 ULONG refCount = InterlockedIncrement(&This->ref);
41
42 return refCount;
43 }
44
45 static
46 ULONG
47 WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface)48 IClassFactory_fnRelease(
49 LPCLASSFACTORY iface)
50 {
51 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
52 ULONG refCount = InterlockedDecrement(&This->ref);
53
54 if (!refCount)
55 {
56 CoTaskMemFree(This);
57 return 0;
58 }
59 return refCount;
60 }
61
62 static
63 HRESULT
64 WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pUnkOuter,REFIID riid,LPVOID * ppvObject)65 IClassFactory_fnCreateInstance(
66 LPCLASSFACTORY iface,
67 LPUNKNOWN pUnkOuter,
68 REFIID riid,
69 LPVOID *ppvObject)
70 {
71 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
72
73 *ppvObject = NULL;
74
75 if ( This->riidInst==NULL || IsEqualCLSID(riid, This->riidInst) || IsEqualCLSID(riid, &IID_IUnknown) )
76 {
77 return This->lpfnCI(pUnkOuter, riid, ppvObject);
78 }
79
80 return E_NOINTERFACE;
81 }
82
83 static
84 HRESULT
IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL fLock)85 WINAPI IClassFactory_fnLockServer(
86 LPCLASSFACTORY iface,
87 BOOL fLock)
88 {
89 //IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
90 return E_NOTIMPL;
91 }
92
93
94 static const IClassFactoryVtbl dclfvt =
95 {
96 IClassFactory_fnQueryInterface,
97 IClassFactory_fnAddRef,
98 IClassFactory_fnRelease,
99 IClassFactory_fnCreateInstance,
100 IClassFactory_fnLockServer
101 };
102
103
104 IClassFactory *
IClassFactory_fnConstructor(LPFNCREATEINSTANCE lpfnCI,PLONG pcRefDll,REFIID riidInst)105 IClassFactory_fnConstructor(
106 LPFNCREATEINSTANCE lpfnCI,
107 PLONG pcRefDll,
108 REFIID riidInst)
109 {
110 IClassFactoryImpl* lpclf;
111
112 lpclf = CoTaskMemAlloc(sizeof(IClassFactoryImpl));
113 lpclf->ref = 1;
114 lpclf->lpVtbl = &dclfvt;
115 lpclf->lpfnCI = lpfnCI;
116
117 if (pcRefDll)
118 InterlockedIncrement(pcRefDll);
119 lpclf->riidInst = riidInst;
120
121 return (LPCLASSFACTORY)lpclf;
122 }
123
124
125