shell32: Return empty list instead of NULL.
[wine.git] / dlls / ddrawex / main.c
blobd1c0fda2d3a78787fdcf5b9e7140be069aab9e42
1 /* DirectDrawEx
3 * Copyright 2006 Ulrich Czekalla
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
23 #define COBJMACROS
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "objbase.h"
28 #include "rpcproxy.h"
30 #include "ddraw.h"
32 #include "initguid.h"
33 #include "ddrawex_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
37 static HINSTANCE instance;
39 /******************************************************************************
40 * DirectDraw ClassFactory implementation
41 ******************************************************************************/
42 typedef struct
44 IClassFactory IClassFactory_iface;
45 LONG ref;
46 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
47 } IClassFactoryImpl;
49 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
51 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 /*******************************************************************************
55 * IDirectDrawClassFactory::QueryInterface
57 *******************************************************************************/
58 static HRESULT WINAPI IDirectDrawClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID riid,
59 void **obj)
61 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), obj);
63 if (IsEqualGUID(riid, &IID_IUnknown)
64 || IsEqualGUID(riid, &IID_IClassFactory))
66 IClassFactory_AddRef(iface);
67 *obj = iface;
68 return S_OK;
71 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
73 *obj = NULL;
74 return E_NOINTERFACE;
77 /*******************************************************************************
78 * IDirectDrawClassFactory::AddRef
80 *******************************************************************************/
81 static ULONG WINAPI IDirectDrawClassFactoryImpl_AddRef(IClassFactory *iface)
83 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
84 ULONG ref = InterlockedIncrement(&This->ref);
86 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
88 return ref;
91 /*******************************************************************************
92 * IDirectDrawClassFactory::Release
94 *******************************************************************************/
95 static ULONG WINAPI IDirectDrawClassFactoryImpl_Release(IClassFactory *iface)
97 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
98 ULONG ref = InterlockedDecrement(&This->ref);
100 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
102 if (ref == 0)
103 HeapFree(GetProcessHeap(), 0, This);
105 return ref;
109 /*******************************************************************************
110 * IDirectDrawClassFactory::CreateInstance
112 *******************************************************************************/
113 static HRESULT WINAPI IDirectDrawClassFactoryImpl_CreateInstance(IClassFactory *iface,
114 IUnknown *UnkOuter, REFIID riid, void **obj)
116 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
118 TRACE("(%p)->(%p,%s,%p)\n",This,UnkOuter,debugstr_guid(riid),obj);
120 return This->pfnCreateInstance(UnkOuter, riid, obj);
123 /*******************************************************************************
124 * IDirectDrawClassFactory::LockServer
126 *******************************************************************************/
127 static HRESULT WINAPI IDirectDrawClassFactoryImpl_LockServer(IClassFactory *iface,BOOL dolock)
129 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
131 FIXME("(%p)->(%d),stub!\n",This,dolock);
133 return S_OK;
137 /*******************************************************************************
138 * The class factory VTable
139 *******************************************************************************/
140 static const IClassFactoryVtbl IClassFactory_Vtbl =
142 IDirectDrawClassFactoryImpl_QueryInterface,
143 IDirectDrawClassFactoryImpl_AddRef,
144 IDirectDrawClassFactoryImpl_Release,
145 IDirectDrawClassFactoryImpl_CreateInstance,
146 IDirectDrawClassFactoryImpl_LockServer
150 /******************************************************************************
151 * DirectDrawFactory implementation
152 ******************************************************************************/
153 typedef struct
155 IDirectDrawFactory IDirectDrawFactory_iface;
156 LONG ref;
157 } IDirectDrawFactoryImpl;
159 static inline IDirectDrawFactoryImpl *impl_from_IDirectDrawFactory(IDirectDrawFactory *iface)
161 return CONTAINING_RECORD(iface, IDirectDrawFactoryImpl, IDirectDrawFactory_iface);
164 /*******************************************************************************
165 * IDirectDrawFactory::QueryInterface
167 *******************************************************************************/
168 static HRESULT WINAPI IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface, REFIID riid,
169 void **obj)
171 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), obj);
173 if (IsEqualGUID(riid, &IID_IUnknown)
174 || IsEqualGUID(riid, &IID_IDirectDrawFactory))
176 IDirectDrawFactory_AddRef(iface);
177 *obj = iface;
178 return S_OK;
181 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
183 *obj = NULL;
184 return E_NOINTERFACE;
187 /*******************************************************************************
188 * IDirectDrawFactory::AddRef
190 *******************************************************************************/
191 static ULONG WINAPI IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
193 IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
194 ULONG ref = InterlockedIncrement(&This->ref);
196 TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
198 return ref;
201 /*******************************************************************************
202 * IDirectDrawFactory::Release
204 *******************************************************************************/
205 static ULONG WINAPI IDirectDrawFactoryImpl_Release(IDirectDrawFactory *iface)
207 IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
208 ULONG ref = InterlockedDecrement(&This->ref);
210 TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
212 if (ref == 0)
213 HeapFree(GetProcessHeap(), 0, This);
215 return ref;
218 /*******************************************************************************
219 * IDirectDrawFactoryImpl_DirectDrawEnumerate
220 *******************************************************************************/
221 static HRESULT WINAPI
222 IDirectDrawFactoryImpl_DirectDrawEnumerate(IDirectDrawFactory* iface,
223 LPDDENUMCALLBACKW lpCallback,
224 LPVOID lpContext)
226 FIXME("Stub!\n");
227 return E_FAIL;
231 /*******************************************************************************
232 * Direct Draw Factory VTable
233 *******************************************************************************/
234 static const IDirectDrawFactoryVtbl IDirectDrawFactory_Vtbl =
236 IDirectDrawFactoryImpl_QueryInterface,
237 IDirectDrawFactoryImpl_AddRef,
238 IDirectDrawFactoryImpl_Release,
239 IDirectDrawFactoryImpl_CreateDirectDraw,
240 IDirectDrawFactoryImpl_DirectDrawEnumerate,
243 /***********************************************************************
244 * CreateDirectDrawFactory
246 ***********************************************************************/
247 static HRESULT
248 CreateDirectDrawFactory(IUnknown* UnkOuter, REFIID iid, void **obj)
250 HRESULT hr;
251 IDirectDrawFactoryImpl *This = NULL;
253 TRACE("(%p,%s,%p)\n", UnkOuter, debugstr_guid(iid), obj);
255 if (UnkOuter != NULL)
256 return CLASS_E_NOAGGREGATION;
258 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawFactoryImpl));
260 if(!This)
262 ERR("Out of memory when creating DirectDraw\n");
263 return E_OUTOFMEMORY;
266 This->IDirectDrawFactory_iface.lpVtbl = &IDirectDrawFactory_Vtbl;
268 hr = IDirectDrawFactory_QueryInterface(&This->IDirectDrawFactory_iface, iid, obj);
270 if (FAILED(hr))
271 HeapFree(GetProcessHeap(), 0, This);
273 return hr;
277 /*******************************************************************************
278 * DllCanUnloadNow [DDRAWEX.@] Determines whether the DLL is in use.
280 HRESULT WINAPI DllCanUnloadNow(void)
282 return S_FALSE;
286 /*******************************************************************************
287 * DllGetClassObject [DDRAWEX.@]
289 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
291 IClassFactoryImpl *factory;
293 TRACE("ddrawex (%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
295 if (!IsEqualGUID( &IID_IClassFactory, riid)
296 && !IsEqualGUID( &IID_IUnknown, riid))
297 return E_NOINTERFACE;
299 if (!IsEqualGUID(&CLSID_DirectDrawFactory, rclsid))
301 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
302 return CLASS_E_CLASSNOTAVAILABLE;
305 factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
306 if (factory == NULL) return E_OUTOFMEMORY;
308 factory->IClassFactory_iface.lpVtbl = &IClassFactory_Vtbl;
309 factory->ref = 1;
311 factory->pfnCreateInstance = CreateDirectDrawFactory;
313 *ppv = factory;
315 return S_OK;
319 /***********************************************************************
320 * DllMain
322 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
324 switch (reason)
326 case DLL_PROCESS_ATTACH:
327 instance = hInstDLL;
328 DisableThreadLibraryCalls( hInstDLL );
329 break;
331 return TRUE;
334 /***********************************************************************
335 * DllRegisterServer (DDRAWEX.@)
337 HRESULT WINAPI DllRegisterServer(void)
339 return __wine_register_resources( instance );
342 /***********************************************************************
343 * DllUnregisterServer (DDRAWEX.@)
345 HRESULT WINAPI DllUnregisterServer(void)
347 return __wine_unregister_resources( instance );