d3dcompiler: Use an iface instead of a vtbl pointer in d3dcompiler_shader_reflection.
[wine] / dlls / ddrawex / main.c
1 /*        DirectDrawEx
2  *
3  * Copyright 2006 Ulrich Czekalla
4  *
5  * This file contains the (internal) driver registration functions,
6  * driver enumeration APIs and DirectDraw creation functions.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23
24 #include "wine/debug.h"
25
26 #define COBJMACROS
27
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "objbase.h"
31 #include "rpcproxy.h"
32
33 #include "ddraw.h"
34
35 #include "initguid.h"
36 #include "ddrawex_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
39
40 static HINSTANCE instance;
41
42 /*******************************************************************************
43  * IDirectDrawClassFactory::QueryInterface
44  *
45  *******************************************************************************/
46 static HRESULT WINAPI
47 IDirectDrawClassFactoryImpl_QueryInterface(IClassFactory *iface,
48                     REFIID riid,
49                     void **obj)
50 {
51     IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
52
53     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
54
55     if (IsEqualGUID(riid, &IID_IUnknown)
56         || IsEqualGUID(riid, &IID_IClassFactory))
57     {
58         IClassFactory_AddRef(iface);
59         *obj = This;
60         return S_OK;
61     }
62
63     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),obj);
64     return E_NOINTERFACE;
65 }
66
67 /*******************************************************************************
68  * IDirectDrawClassFactory::AddRef
69  *
70  *******************************************************************************/
71 static ULONG WINAPI
72 IDirectDrawClassFactoryImpl_AddRef(IClassFactory *iface)
73 {
74     IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
75     ULONG ref = InterlockedIncrement(&This->ref);
76
77     TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
78
79     return ref;
80 }
81
82 /*******************************************************************************
83  * IDirectDrawClassFactory::Release
84  *
85  *******************************************************************************/
86 static ULONG WINAPI
87 IDirectDrawClassFactoryImpl_Release(IClassFactory *iface)
88 {
89     IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
90     ULONG ref = InterlockedDecrement(&This->ref);
91     TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
92
93     if (ref == 0)
94         HeapFree(GetProcessHeap(), 0, This);
95
96     return ref;
97 }
98
99
100 /*******************************************************************************
101  * IDirectDrawClassFactory::CreateInstance
102  *
103  *******************************************************************************/
104 static HRESULT WINAPI
105 IDirectDrawClassFactoryImpl_CreateInstance(IClassFactory *iface,
106                                            IUnknown *UnkOuter,
107                                            REFIID riid,
108                                            void **obj)
109 {
110     IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
111
112     TRACE("(%p)->(%p,%s,%p)\n",This,UnkOuter,debugstr_guid(riid),obj);
113
114     return This->pfnCreateInstance(UnkOuter, riid, obj);
115 }
116
117 /*******************************************************************************
118  * IDirectDrawClassFactory::LockServer
119  *
120  *******************************************************************************/
121 static HRESULT WINAPI
122 IDirectDrawClassFactoryImpl_LockServer(IClassFactory *iface,BOOL dolock)
123 {
124     IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
125     FIXME("(%p)->(%d),stub!\n",This,dolock);
126     return S_OK;
127 }
128
129
130 /*******************************************************************************
131  * The class factory VTable
132  *******************************************************************************/
133 static const IClassFactoryVtbl IClassFactory_Vtbl =
134 {
135     IDirectDrawClassFactoryImpl_QueryInterface,
136     IDirectDrawClassFactoryImpl_AddRef,
137     IDirectDrawClassFactoryImpl_Release,
138     IDirectDrawClassFactoryImpl_CreateInstance,
139     IDirectDrawClassFactoryImpl_LockServer
140 };
141
142
143 /*******************************************************************************
144  * IDirectDrawFactory::QueryInterface
145  *
146  *******************************************************************************/
147 static HRESULT WINAPI
148 IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface,
149                     REFIID riid,
150                     void **obj)
151 {
152     IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
153
154     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
155
156     if (IsEqualGUID(riid, &IID_IUnknown)
157         || IsEqualGUID(riid, &IID_IDirectDrawFactory))
158     {
159         IDirectDrawFactory_AddRef(iface);
160         *obj = This;
161         return S_OK;
162     }
163
164     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),obj);
165     return E_NOINTERFACE;
166 }
167
168 /*******************************************************************************
169  * IDirectDrawFactory::AddRef
170  *
171  *******************************************************************************/
172 static ULONG WINAPI
173 IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
174 {
175     IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
176     ULONG ref = InterlockedIncrement(&This->ref);
177
178     TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
179
180     return ref;
181 }
182
183 /*******************************************************************************
184  * IDirectDrawFactory::Release
185  *
186  *******************************************************************************/
187 static ULONG WINAPI
188 IDirectDrawFactoryImpl_Release(IDirectDrawFactory *iface)
189 {
190     IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
191     ULONG ref = InterlockedDecrement(&This->ref);
192     TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
193
194     if (ref == 0)
195         HeapFree(GetProcessHeap(), 0, This);
196
197     return ref;
198 }
199
200 /*******************************************************************************
201  * IDirectDrawFactoryImpl_DirectDrawEnumerate
202  *******************************************************************************/
203 static HRESULT WINAPI
204 IDirectDrawFactoryImpl_DirectDrawEnumerate(IDirectDrawFactory* iface,
205                                            LPDDENUMCALLBACKW lpCallback,
206                                            LPVOID lpContext)
207 {
208     FIXME("Stub!\n");
209     return E_FAIL;
210 }
211
212
213 /*******************************************************************************
214  * Direct Draw Factory VTable
215  *******************************************************************************/
216 static const IDirectDrawFactoryVtbl IDirectDrawFactory_Vtbl =
217 {
218     IDirectDrawFactoryImpl_QueryInterface,
219     IDirectDrawFactoryImpl_AddRef,
220     IDirectDrawFactoryImpl_Release,
221     IDirectDrawFactoryImpl_CreateDirectDraw,
222     IDirectDrawFactoryImpl_DirectDrawEnumerate,
223 };
224
225 /***********************************************************************
226  * CreateDirectDrawFactory
227  *
228  ***********************************************************************/
229 static HRESULT
230 CreateDirectDrawFactory(IUnknown* UnkOuter, REFIID iid, void **obj)
231 {
232     HRESULT hr;
233     IDirectDrawFactoryImpl *This = NULL;
234
235     TRACE("(%p,%s,%p)\n", UnkOuter, debugstr_guid(iid), obj);
236
237     if (UnkOuter != NULL)
238         return CLASS_E_NOAGGREGATION;
239
240     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawFactoryImpl));
241
242     if(!This)
243     {
244         ERR("Out of memory when creating DirectDraw\n");
245         return E_OUTOFMEMORY;
246     }
247
248     This->lpVtbl = &IDirectDrawFactory_Vtbl;
249
250     hr = IDirectDrawFactory_QueryInterface((IDirectDrawFactory *)This, iid,  obj);
251
252     if (FAILED(hr))
253         HeapFree(GetProcessHeap(), 0, This);
254
255     return hr;
256 }
257
258
259 /*******************************************************************************
260  * DllCanUnloadNow [DDRAWEX.@]  Determines whether the DLL is in use.
261  */
262 HRESULT WINAPI DllCanUnloadNow(void)
263 {
264     return S_FALSE;
265 }
266
267
268 /*******************************************************************************
269  * DllGetClassObject [DDRAWEX.@]
270  */
271 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
272 {
273     IClassFactoryImpl *factory;
274
275     TRACE("ddrawex (%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
276
277     if (!IsEqualGUID( &IID_IClassFactory, riid)
278         && !IsEqualGUID( &IID_IUnknown, riid))
279         return E_NOINTERFACE;
280
281     if (!IsEqualGUID(&CLSID_DirectDrawFactory, rclsid))
282     {
283         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
284         return CLASS_E_CLASSNOTAVAILABLE;
285     }
286
287     factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
288     if (factory == NULL) return E_OUTOFMEMORY;
289
290     factory->lpVtbl = &IClassFactory_Vtbl;
291     factory->ref = 1;
292
293     factory->pfnCreateInstance = CreateDirectDrawFactory;
294
295     *ppv = factory;
296
297     return S_OK;
298 }
299
300
301 /***********************************************************************
302  * DllMain
303  */
304 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
305 {
306     switch (reason)
307     {
308     case DLL_PROCESS_ATTACH:
309         instance = hInstDLL;
310         DisableThreadLibraryCalls( hInstDLL );
311         break;
312     }
313     return TRUE;
314 }
315
316 /***********************************************************************
317  *              DllRegisterServer (DDRAWEX.@)
318  */
319 HRESULT WINAPI DllRegisterServer(void)
320 {
321     return __wine_register_resources( instance, NULL );
322 }
323
324 /***********************************************************************
325  *              DllUnregisterServer (DDRAWEX.@)
326  */
327 HRESULT WINAPI DllUnregisterServer(void)
328 {
329     return __wine_unregister_resources( instance, NULL );
330 }