Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / ddrawex / main.c
blobb3d4b2656e83056eeb5ea68e871f9d08251f4f12
1 /* DirectDrawEx
3 * Copyright 2006 Ulrich Czekalla
5 * This file contains the (internal) driver registration functions,
6 * driver enumeration APIs and DirectDraw creation functions.
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.
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.
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
24 #include "wine/debug.h"
26 #define COBJMACROS
28 #include "winbase.h"
29 #include "wingdi.h"
31 #include "ddraw.h"
33 #include "initguid.h"
34 #include "ddrawex_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
39 /*******************************************************************************
40 * IDirectDrawClassFactory::QueryInterface
42 *******************************************************************************/
43 static HRESULT WINAPI
44 IDirectDrawClassFactoryImpl_QueryInterface(IClassFactory *iface,
45 REFIID riid,
46 void **obj)
48 IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
50 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
52 if (IsEqualGUID(riid, &IID_IUnknown)
53 || IsEqualGUID(riid, &IID_IClassFactory))
55 IClassFactory_AddRef(iface);
56 *obj = This;
57 return S_OK;
60 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),obj);
61 return E_NOINTERFACE;
64 /*******************************************************************************
65 * IDirectDrawClassFactory::AddRef
67 *******************************************************************************/
68 static ULONG WINAPI
69 IDirectDrawClassFactoryImpl_AddRef(IClassFactory *iface)
71 IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
72 ULONG ref = InterlockedIncrement(&This->ref);
74 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
76 return ref;
79 /*******************************************************************************
80 * IDirectDrawClassFactory::Release
82 *******************************************************************************/
83 static ULONG WINAPI
84 IDirectDrawClassFactoryImpl_Release(IClassFactory *iface)
86 IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
87 ULONG ref = InterlockedDecrement(&This->ref);
88 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
90 if (ref == 0)
91 HeapFree(GetProcessHeap(), 0, This);
93 return ref;
97 /*******************************************************************************
98 * IDirectDrawClassFactory::CreateInstance
100 *******************************************************************************/
101 static HRESULT WINAPI
102 IDirectDrawClassFactoryImpl_CreateInstance(IClassFactory *iface,
103 IUnknown *UnkOuter,
104 REFIID riid,
105 void **obj)
107 IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
109 TRACE("(%p)->(%p,%s,%p)\n",This,UnkOuter,debugstr_guid(riid),obj);
111 return This->pfnCreateInstance(UnkOuter, riid, obj);
114 /*******************************************************************************
115 * IDirectDrawClassFactory::LockServer
117 *******************************************************************************/
118 static HRESULT WINAPI
119 IDirectDrawClassFactoryImpl_LockServer(IClassFactory *iface,BOOL dolock)
121 IClassFactoryImpl *This = (IClassFactoryImpl*) iface;
122 FIXME("(%p)->(%d),stub!\n",This,dolock);
123 return S_OK;
127 /*******************************************************************************
128 * The class factory VTable
129 *******************************************************************************/
130 static const IClassFactoryVtbl IClassFactory_Vtbl =
132 IDirectDrawClassFactoryImpl_QueryInterface,
133 IDirectDrawClassFactoryImpl_AddRef,
134 IDirectDrawClassFactoryImpl_Release,
135 IDirectDrawClassFactoryImpl_CreateInstance,
136 IDirectDrawClassFactoryImpl_LockServer
140 /*******************************************************************************
141 * IDirectDrawFactory::QueryInterface
143 *******************************************************************************/
144 static HRESULT WINAPI
145 IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface,
146 REFIID riid,
147 void **obj)
149 IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
151 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
153 if (IsEqualGUID(riid, &IID_IUnknown)
154 || IsEqualGUID(riid, &IID_IDirectDrawFactory))
156 IDirectDrawFactory_AddRef(iface);
157 *obj = This;
158 return S_OK;
161 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),obj);
162 return E_NOINTERFACE;
165 /*******************************************************************************
166 * IDirectDrawFactory::AddRef
168 *******************************************************************************/
169 static ULONG WINAPI
170 IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
172 IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
173 ULONG ref = InterlockedIncrement(&This->ref);
175 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
177 return ref;
180 /*******************************************************************************
181 * IDirectDrawFactory::Release
183 *******************************************************************************/
184 static ULONG WINAPI
185 IDirectDrawFactoryImpl_Release(IDirectDrawFactory *iface)
187 IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
188 ULONG ref = InterlockedDecrement(&This->ref);
189 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
191 if (ref == 0)
192 HeapFree(GetProcessHeap(), 0, This);
194 return ref;
198 /*******************************************************************************
199 * IDirectDrawFactoryImpl_CreateDirectDraw
200 *******************************************************************************/
201 static HRESULT WINAPI
202 IDirectDrawFactoryImpl_CreateDirectDraw(IDirectDrawFactory* iface,
203 GUID * pGUID,
204 HWND hWnd,
205 DWORD dwCoopLevelFlags,
206 DWORD dwReserved,
207 IUnknown *pUnkOuter,
208 IDirectDraw **ppDirectDraw)
210 HRESULT hr;
211 IDirectDraw *pddraw7;
213 TRACE("\n");
215 hr = DirectDrawCreateEx(pGUID, (void**)&pddraw7, &IID_IDirectDraw7, pUnkOuter);
217 if (FAILED(hr))
218 return hr;
220 hr = IDirectDraw_QueryInterface(pddraw7, &IID_IDirectDraw3, (void**)ppDirectDraw);
221 IDirectDraw_Release(pddraw7);
222 if (FAILED(hr))
223 return hr;
225 hr = IDirectDraw_SetCooperativeLevel(*ppDirectDraw, hWnd, dwCoopLevelFlags);
226 if (FAILED(hr))
227 IDirectDraw_Release(*ppDirectDraw);
229 return hr;
233 /*******************************************************************************
234 * IDirectDrawFactoryImpl_DirectDrawEnumerate
235 *******************************************************************************/
236 static HRESULT WINAPI
237 IDirectDrawFactoryImpl_DirectDrawEnumerate(IDirectDrawFactory* iface,
238 LPDDENUMCALLBACKW lpCallback,
239 LPVOID lpContext)
241 FIXME("Stub!\n");
242 return E_FAIL;
246 /*******************************************************************************
247 * Direct Draw Factory VTable
248 *******************************************************************************/
249 static const IDirectDrawFactoryVtbl IDirectDrawFactory_Vtbl =
251 IDirectDrawFactoryImpl_QueryInterface,
252 IDirectDrawFactoryImpl_AddRef,
253 IDirectDrawFactoryImpl_Release,
254 IDirectDrawFactoryImpl_CreateDirectDraw,
255 IDirectDrawFactoryImpl_DirectDrawEnumerate,
258 /***********************************************************************
259 * CreateDirectDrawFactory
261 ***********************************************************************/
262 static HRESULT
263 CreateDirectDrawFactory(IUnknown* UnkOuter, REFIID iid, void **obj)
265 HRESULT hr;
266 IDirectDrawFactoryImpl *This = NULL;
268 TRACE("(%p,%s,%p)\n", UnkOuter, debugstr_guid(iid), obj);
270 if (UnkOuter != NULL)
271 return CLASS_E_NOAGGREGATION;
273 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawFactoryImpl));
275 if(!This)
277 ERR("Out of memory when creating DirectDraw\n");
278 return E_OUTOFMEMORY;
281 This->lpVtbl = &IDirectDrawFactory_Vtbl;
283 hr = IDirectDrawFactory_QueryInterface((IDirectDrawFactory *)This, iid, obj);
285 if (FAILED(hr))
286 HeapFree(GetProcessHeap(), 0, This);
288 return hr;
292 /*******************************************************************************
293 * DllCanUnloadNow [DDRAWEX.@] Determines whether the DLL is in use.
295 HRESULT WINAPI DllCanUnloadNow(void)
297 FIXME("(void): stub\n");
298 return S_FALSE;
302 /*******************************************************************************
303 * DllGetClassObject [DDRAWEX.@]
305 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
307 IClassFactoryImpl *factory;
309 TRACE("ddrawex (%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
311 if (!IsEqualGUID( &IID_IClassFactory, riid)
312 && !IsEqualGUID( &IID_IUnknown, riid))
313 return E_NOINTERFACE;
315 if (!IsEqualGUID(&CLSID_DirectDrawFactory, rclsid))
317 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
318 return CLASS_E_CLASSNOTAVAILABLE;
321 factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
322 if (factory == NULL) return E_OUTOFMEMORY;
324 factory->lpVtbl = &IClassFactory_Vtbl;
325 factory->ref = 1;
327 factory->pfnCreateInstance = CreateDirectDrawFactory;
329 *ppv = (IClassFactory*) factory;
331 return S_OK;
335 /***********************************************************************
336 * DllMain (DDRAWEX.0)
338 ***********************************************************************/
339 BOOL WINAPI
340 DllMain(HINSTANCE hInstDLL,
341 DWORD Reason,
342 void *lpv)
344 TRACE("(%p,%x,%p)\n", hInstDLL, Reason, lpv);
345 return TRUE;