Made all 16<->32 HWND conversions use explicit functions instead of
[wine/multimedia.git] / dlls / dplayx / lobbysp.c
blob3a1883088b97d7e30b998a84d7dc88efd8193fb3
1 /* This contains the implementation of the Lobby Service
2 * Providers interface required to communicate with Direct Play
4 * Copyright 2001 Peter Hunnisett <hunnise@nortelnetworks.com>
5 */
7 #include "winerror.h"
8 #include "debugtools.h"
10 #include "lobbysp.h"
11 #include "dplay_global.h"
12 #include "dpinit.h"
14 DEFAULT_DEBUG_CHANNEL(dplay);
16 /* Prototypes */
17 static BOOL DPLSP_CreateIUnknown( LPVOID lpSP );
18 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP );
19 static BOOL DPLSP_CreateDPLobbySP( LPVOID lpSP, IDirectPlay2Impl* dp );
20 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP );
23 /* Predefine the interface */
24 typedef struct IDPLobbySPImpl IDPLobbySPImpl;
26 typedef struct tagDPLobbySPIUnknownData
28 ULONG ulObjRef;
29 CRITICAL_SECTION DPLSP_lock;
30 } DPLobbySPIUnknownData;
32 typedef struct tagDPLobbySPData
34 IDirectPlay2Impl* dplay;
35 } DPLobbySPData;
37 #define DPLSP_IMPL_FIELDS \
38 ULONG ulInterfaceRef; \
39 DPLobbySPIUnknownData* unk; \
40 DPLobbySPData* sp;
42 struct IDPLobbySPImpl
44 ICOM_VFIELD(IDPLobbySP);
45 DPLSP_IMPL_FIELDS
48 /* Forward declaration of virtual tables */
49 static ICOM_VTABLE(IDPLobbySP) dpLobbySPVT;
51 extern
52 HRESULT DPLSP_CreateInterface( REFIID riid, LPVOID* ppvObj, IDirectPlay2Impl* dp )
54 TRACE( " for %s\n", debugstr_guid( riid ) );
56 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
57 sizeof( IDPLobbySPImpl ) );
59 if( *ppvObj == NULL )
61 return DPERR_OUTOFMEMORY;
64 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
66 ICOM_THIS(IDPLobbySPImpl,*ppvObj);
67 ICOM_VTBL(This) = &dpLobbySPVT;
69 else
71 /* Unsupported interface */
72 HeapFree( GetProcessHeap(), 0, *ppvObj );
73 *ppvObj = NULL;
75 return E_NOINTERFACE;
78 /* Initialize it */
79 if( DPLSP_CreateIUnknown( *ppvObj ) &&
80 DPLSP_CreateDPLobbySP( *ppvObj, dp )
83 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
84 return S_OK;
87 /* Initialize failed, destroy it */
88 DPLSP_DestroyDPLobbySP( *ppvObj );
89 DPLSP_DestroyIUnknown( *ppvObj );
91 HeapFree( GetProcessHeap(), 0, *ppvObj );
92 *ppvObj = NULL;
94 return DPERR_NOMEMORY;
97 static BOOL DPLSP_CreateIUnknown( LPVOID lpSP )
99 ICOM_THIS(IDPLobbySPImpl,lpSP);
101 This->unk = (DPLobbySPIUnknownData*)HeapAlloc( GetProcessHeap(),
102 HEAP_ZERO_MEMORY,
103 sizeof( *(This->unk) ) );
105 if ( This->unk == NULL )
107 return FALSE;
110 InitializeCriticalSection( &This->unk->DPLSP_lock );
112 return TRUE;
115 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP )
117 ICOM_THIS(IDPLobbySPImpl,lpSP);
119 DeleteCriticalSection( &This->unk->DPLSP_lock );
120 HeapFree( GetProcessHeap(), 0, This->unk );
122 return TRUE;
125 static BOOL DPLSP_CreateDPLobbySP( LPVOID lpSP, IDirectPlay2Impl* dp )
127 ICOM_THIS(IDPLobbySPImpl,lpSP);
129 This->sp = (DPLobbySPData*)HeapAlloc( GetProcessHeap(),
130 HEAP_ZERO_MEMORY,
131 sizeof( *(This->sp) ) );
133 if ( This->sp == NULL )
135 return FALSE;
138 This->sp->dplay = dp;
140 /* Normally we should be keeping a reference, but since only the dplay
141 * interface that created us can destroy us, we do not keep a reference
142 * to it (ie we'd be stuck with always having one reference to the dplay
143 * object, and hence us, around).
144 * NOTE: The dp object does reference count us.
146 * FIXME: This is a kludge to get around a problem where a queryinterface
147 * is used to get a new interface and then is closed. We will then
148 * reference garbage. However, with this we will never deallocate
149 * the interface we store. The correct fix is to require all
150 * DP internal interfaces to use the This->dp2 interface which
151 * should be changed to This->dp
153 IDirectPlayX_AddRef( (LPDIRECTPLAY2)dp );
156 return TRUE;
159 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP )
161 ICOM_THIS(IDPLobbySPImpl,lpSP);
163 HeapFree( GetProcessHeap(), 0, This->sp );
165 return TRUE;
168 static
169 HRESULT WINAPI DPLSP_QueryInterface
170 ( LPDPLOBBYSP iface,
171 REFIID riid,
172 LPVOID* ppvObj
175 ICOM_THIS(IDPLobbySPImpl,iface);
176 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
178 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
179 sizeof( *This ) );
181 if( *ppvObj == NULL )
183 return DPERR_OUTOFMEMORY;
186 CopyMemory( *ppvObj, This, sizeof( *This ) );
187 (*(IDPLobbySPImpl**)ppvObj)->ulInterfaceRef = 0;
189 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
191 ICOM_THIS(IDPLobbySPImpl,*ppvObj);
192 ICOM_VTBL(This) = &dpLobbySPVT;
194 else
196 /* Unsupported interface */
197 HeapFree( GetProcessHeap(), 0, *ppvObj );
198 *ppvObj = NULL;
200 return E_NOINTERFACE;
203 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
205 return S_OK;
208 static
209 ULONG WINAPI DPLSP_AddRef
210 ( LPDPLOBBYSP iface )
212 ULONG ulInterfaceRefCount, ulObjRefCount;
213 ICOM_THIS(IDPLobbySPImpl,iface);
215 ulObjRefCount = InterlockedIncrement( &This->unk->ulObjRef );
216 ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );
218 TRACE( "ref count incremented to %lu:%lu for %p\n",
219 ulInterfaceRefCount, ulObjRefCount, This );
221 return ulObjRefCount;
224 static
225 ULONG WINAPI DPLSP_Release
226 ( LPDPLOBBYSP iface )
228 ULONG ulInterfaceRefCount, ulObjRefCount;
229 ICOM_THIS(IDPLobbySPImpl,iface);
231 ulObjRefCount = InterlockedDecrement( &This->unk->ulObjRef );
232 ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );
234 TRACE( "ref count decremented to %lu:%lu for %p\n",
235 ulInterfaceRefCount, ulObjRefCount, This );
237 /* Deallocate if this is the last reference to the object */
238 if( ulObjRefCount == 0 )
240 DPLSP_DestroyDPLobbySP( This );
241 DPLSP_DestroyIUnknown( This );
244 if( ulInterfaceRefCount == 0 )
246 HeapFree( GetProcessHeap(), 0, This );
249 return ulInterfaceRefCount;
252 static
253 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
254 ( LPDPLOBBYSP iface,
255 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
258 ICOM_THIS(IDPLobbySPImpl,iface);
259 FIXME( "(%p)->(%p):stub\n", This, argtg );
260 return DP_OK;
263 static
264 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
265 ( LPDPLOBBYSP iface,
266 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
269 ICOM_THIS(IDPLobbySPImpl,iface);
270 FIXME( "(%p)->(%p):stub\n", This, arptg );
271 return DP_OK;
274 static
275 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
276 ( LPDPLOBBYSP iface,
277 LPSPDATA_CREATEREMOTEGROUP crg
280 ICOM_THIS(IDPLobbySPImpl,iface);
281 FIXME( "(%p)->(%p):stub\n", This, crg );
282 return DP_OK;
285 static
286 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
287 ( LPDPLOBBYSP iface,
288 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
291 ICOM_THIS(IDPLobbySPImpl,iface);
292 FIXME( "(%p)->(%p):stub\n", This, crgig );
293 return DP_OK;
296 static
297 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
298 ( LPDPLOBBYSP iface,
299 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
302 ICOM_THIS(IDPLobbySPImpl,iface);
303 FIXME( "(%p)->(%p):stub\n", This, drgfg );
304 return DP_OK;
307 static
308 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
309 ( LPDPLOBBYSP iface,
310 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
313 ICOM_THIS(IDPLobbySPImpl,iface);
314 FIXME( "(%p)->(%p):stub\n", This, drpfg );
315 return DP_OK;
318 static
319 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
320 ( LPDPLOBBYSP iface,
321 LPSPDATA_DESTROYREMOTEGROUP drg
324 ICOM_THIS(IDPLobbySPImpl,iface);
325 FIXME( "(%p)->(%p):stub\n", This, drg );
326 return DP_OK;
329 static
330 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
331 ( LPDPLOBBYSP iface,
332 LPSPDATA_ENUMSESSIONSRESPONSE er
335 ICOM_THIS(IDPLobbySPImpl,iface);
336 FIXME( "(%p)->(%p):stub\n", This, er );
337 return DP_OK;
340 static
341 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
342 ( LPDPLOBBYSP iface,
343 LPVOID* lplpData
346 ICOM_THIS(IDPLobbySPImpl,iface);
347 FIXME( "(%p)->(%p):stub\n", This, lplpData );
348 return DP_OK;
351 static
352 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
353 ( LPDPLOBBYSP iface,
354 LPSPDATA_HANDLEMESSAGE hm
357 ICOM_THIS(IDPLobbySPImpl,iface);
358 FIXME( "(%p)->(%p):stub\n", This, hm );
359 return DP_OK;
362 static
363 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
364 ( LPDPLOBBYSP iface,
365 LPSPDATA_CHATMESSAGE cm
368 ICOM_THIS(IDPLobbySPImpl,iface);
369 FIXME( "(%p)->(%p):stub\n", This, cm );
370 return DP_OK;
373 static
374 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
375 ( LPDPLOBBYSP iface,
376 LPSPDATA_SETREMOTEGROUPNAME srgn
379 ICOM_THIS(IDPLobbySPImpl,iface);
380 FIXME( "(%p)->(%p):stub\n", This, srgn );
381 return DP_OK;
384 static
385 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
386 ( LPDPLOBBYSP iface,
387 LPSPDATA_SETREMOTEPLAYERNAME srpn
390 ICOM_THIS(IDPLobbySPImpl,iface);
391 FIXME( "(%p)->(%p):stub\n", This, srpn );
392 return DP_OK;
395 static
396 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
397 ( LPDPLOBBYSP iface,
398 LPSPDATA_SETSESSIONDESC ssd
401 ICOM_THIS(IDPLobbySPImpl,iface);
402 FIXME( "(%p)->(%p):stub\n", This, ssd );
403 return DP_OK;
406 static
407 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
408 ( LPDPLOBBYSP iface,
409 LPVOID lpData
412 ICOM_THIS(IDPLobbySPImpl,iface);
413 FIXME( "(%p)->(%p):stub\n", This, lpData );
414 return DP_OK;
417 static
418 HRESULT WINAPI IDPLobbySPImpl_StartSession
419 ( LPDPLOBBYSP iface,
420 LPSPDATA_STARTSESSIONCOMMAND ssc
423 ICOM_THIS(IDPLobbySPImpl,iface);
424 FIXME( "(%p)->(%p):stub\n", This, ssc );
425 return DP_OK;
429 static struct ICOM_VTABLE(IDPLobbySP) dpLobbySPVT =
431 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
433 DPLSP_QueryInterface,
434 DPLSP_AddRef,
435 DPLSP_Release,
437 IDPLobbySPImpl_AddGroupToGroup,
438 IDPLobbySPImpl_AddPlayerToGroup,
439 IDPLobbySPImpl_CreateGroup,
440 IDPLobbySPImpl_CreateGroupInGroup,
441 IDPLobbySPImpl_DeleteGroupFromGroup,
442 IDPLobbySPImpl_DeletePlayerFromGroup,
443 IDPLobbySPImpl_DestroyGroup,
444 IDPLobbySPImpl_EnumSessionsResponse,
445 IDPLobbySPImpl_GetSPDataPointer,
446 IDPLobbySPImpl_HandleMessage,
447 IDPLobbySPImpl_SendChatMessage,
448 IDPLobbySPImpl_SetGroupName,
449 IDPLobbySPImpl_SetPlayerName,
450 IDPLobbySPImpl_SetSessionDesc,
451 IDPLobbySPImpl_SetSPDataPointer,
452 IDPLobbySPImpl_StartSession