Fix merge r65567.
[reactos.git] / dll / directx / wine / dplayx / dplobby.c
1 /* Direct Play Lobby 2 & 3 Implementation
2 *
3 * Copyright 1998,1999,2000 - Peter Hunnisett
4 *
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.
9 *
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.
14 *
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
18 */
19
20 #include "dplayx_global.h"
21
22 /* Forward declarations for this module helper methods */
23 HRESULT DPL_CreateCompoundAddress ( LPCDPCOMPOUNDADDRESSELEMENT lpElements, DWORD dwElementCount,
24 LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface )DECLSPEC_HIDDEN;
25
26 static HRESULT DPL_CreateAddress( REFGUID guidSP, REFGUID guidDataType, LPCVOID lpData, DWORD dwDataSize,
27 LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface );
28
29
30 /*****************************************************************************
31 * IDirectPlayLobby {1,2,3} implementation structure
32 *
33 * The philosophy behind this extra pointer dereference is that I wanted to
34 * have the same structure for all types of objects without having to do
35 * a lot of casting. I also only wanted to implement an interface in the
36 * object it was "released" with IUnknown interface being implemented in the 1 version.
37 * Of course, with these new interfaces comes the data required to keep the state required
38 * by these interfaces. So, basically, the pointers contain the data associated with
39 * a release. If you use the data associated with release 3 in a release 2 object, you'll
40 * get a run time trap, as that won't have any data.
41 *
42 */
43 struct DPLMSG
44 {
45 DPQ_ENTRY( DPLMSG ) msgs; /* Link to next queued message */
46 };
47 typedef struct DPLMSG* LPDPLMSG;
48
49 typedef struct IDirectPlayLobbyImpl
50 {
51 IDirectPlayLobby IDirectPlayLobby_iface;
52 IDirectPlayLobbyA IDirectPlayLobbyA_iface;
53 IDirectPlayLobby2 IDirectPlayLobby2_iface;
54 IDirectPlayLobby2A IDirectPlayLobby2A_iface;
55 IDirectPlayLobby3 IDirectPlayLobby3_iface;
56 IDirectPlayLobby3A IDirectPlayLobby3A_iface;
57 LONG numIfaces; /* "in use interfaces" refcount */
58 LONG ref, refA, ref2, ref2A, ref3, ref3A;
59 CRITICAL_SECTION lock;
60 HKEY cbkeyhack;
61 DWORD msgtid;
62 DPQ_HEAD( DPLMSG ) msgs; /* List of messages received */
63 } IDirectPlayLobbyImpl;
64
65 static inline IDirectPlayLobbyImpl *impl_from_IDirectPlayLobby( IDirectPlayLobby *iface )
66 {
67 return CONTAINING_RECORD( iface, IDirectPlayLobbyImpl, IDirectPlayLobby_iface );
68 }
69
70 static inline IDirectPlayLobbyImpl *impl_from_IDirectPlayLobbyA( IDirectPlayLobbyA *iface )
71 {
72 return CONTAINING_RECORD( iface, IDirectPlayLobbyImpl, IDirectPlayLobbyA_iface );
73 }
74
75 static inline IDirectPlayLobbyImpl *impl_from_IDirectPlayLobby2( IDirectPlayLobby2 *iface )
76 {
77 return CONTAINING_RECORD( iface, IDirectPlayLobbyImpl, IDirectPlayLobby2_iface );
78 }
79
80 static inline IDirectPlayLobbyImpl *impl_from_IDirectPlayLobby2A( IDirectPlayLobby2A *iface )
81 {
82 return CONTAINING_RECORD( iface, IDirectPlayLobbyImpl, IDirectPlayLobby2A_iface );
83 }
84
85 static inline IDirectPlayLobbyImpl *impl_from_IDirectPlayLobby3( IDirectPlayLobby3 *iface )
86 {
87 return CONTAINING_RECORD( iface, IDirectPlayLobbyImpl, IDirectPlayLobby3_iface );
88 }
89
90 static inline IDirectPlayLobbyImpl *impl_from_IDirectPlayLobby3A( IDirectPlayLobby3A *iface )
91 {
92 return CONTAINING_RECORD( iface, IDirectPlayLobbyImpl, IDirectPlayLobby3A_iface );
93 }
94
95 static void dplobby_destroy(IDirectPlayLobbyImpl *obj)
96 {
97 if ( obj->msgtid )
98 FIXME( "Should kill the msg thread\n" );
99
100 DPQ_DELETEQ( obj->msgs, msgs, LPDPLMSG, cbDeleteElemFromHeap );
101 obj->lock.DebugInfo->Spare[0] = 0;
102 DeleteCriticalSection( &obj->lock );
103 HeapFree( GetProcessHeap(), 0, obj );
104 }
105
106 static HRESULT WINAPI IDirectPlayLobbyAImpl_QueryInterface( IDirectPlayLobbyA *iface, REFIID riid,
107 void **ppv )
108 {
109 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
110 return IDirectPlayLobby_QueryInterface( &This->IDirectPlayLobby3_iface, riid, ppv );
111 }
112
113 static HRESULT WINAPI IDirectPlayLobbyImpl_QueryInterface( IDirectPlayLobby *iface, REFIID riid,
114 void **ppv )
115 {
116 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
117 return IDirectPlayLobby_QueryInterface( &This->IDirectPlayLobby3_iface, riid, ppv );
118 }
119
120 static HRESULT WINAPI IDirectPlayLobby2AImpl_QueryInterface( IDirectPlayLobby2A *iface, REFIID riid,
121 void **ppv )
122 {
123 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
124 return IDirectPlayLobby_QueryInterface( &This->IDirectPlayLobby3_iface, riid, ppv );
125 }
126
127 static HRESULT WINAPI IDirectPlayLobby2Impl_QueryInterface( IDirectPlayLobby2 *iface, REFIID riid,
128 void **ppv )
129 {
130 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
131 return IDirectPlayLobby_QueryInterface( &This->IDirectPlayLobby3_iface, riid, ppv );
132 }
133
134 static HRESULT WINAPI IDirectPlayLobby3AImpl_QueryInterface( IDirectPlayLobby3A *iface, REFIID riid,
135 void **ppv )
136 {
137 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
138 return IDirectPlayLobby_QueryInterface( &This->IDirectPlayLobby3_iface, riid, ppv );
139 }
140
141 static HRESULT WINAPI IDirectPlayLobby3Impl_QueryInterface( IDirectPlayLobby3 *iface, REFIID riid,
142 void **ppv )
143 {
144 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
145
146 if ( IsEqualGUID( &IID_IUnknown, riid ) )
147 {
148 TRACE( "(%p)->(IID_IUnknown %p)\n", This, ppv );
149 *ppv = &This->IDirectPlayLobby_iface;
150 }
151 else if ( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
152 {
153 TRACE( "(%p)->(IID_IDirectPlayLobby %p)\n", This, ppv );
154 *ppv = &This->IDirectPlayLobby_iface;
155 }
156 else if ( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
157 {
158 TRACE( "(%p)->(IID_IDirectPlayLobbyA %p)\n", This, ppv );
159 *ppv = &This->IDirectPlayLobbyA_iface;
160 }
161 else if ( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
162 {
163 TRACE( "(%p)->(IID_IDirectPlayLobby2 %p)\n", This, ppv );
164 *ppv = &This->IDirectPlayLobby2_iface;
165 }
166 else if ( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
167 {
168 TRACE( "(%p)->(IID_IDirectPlayLobby2A %p)\n", This, ppv );
169 *ppv = &This->IDirectPlayLobby2A_iface;
170 }
171 else if ( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
172 {
173 TRACE( "(%p)->(IID_IDirectPlay3 %p)\n", This, ppv );
174 *ppv = &This->IDirectPlayLobby3_iface;
175 }
176 else if ( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
177 {
178 TRACE( "(%p)->(IID_IDirectPlayLobby3A %p)\n", This, ppv );
179 *ppv = &This->IDirectPlayLobby3A_iface;
180 }
181 else
182 {
183 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
184 *ppv = NULL;
185 return E_NOINTERFACE;
186 }
187
188 IUnknown_AddRef((IUnknown*)*ppv);
189 return S_OK;
190 }
191
192 static ULONG WINAPI IDirectPlayLobbyAImpl_AddRef( IDirectPlayLobbyA *iface )
193 {
194 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
195 ULONG ref = InterlockedIncrement( &This->refA );
196
197 TRACE( "(%p) refA=%d\n", This, ref );
198
199 if ( ref == 1 )
200 InterlockedIncrement( &This->numIfaces );
201
202 return ref;
203 }
204
205 static ULONG WINAPI IDirectPlayLobbyImpl_AddRef( IDirectPlayLobby *iface )
206 {
207 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
208 ULONG ref = InterlockedIncrement( &This->ref );
209
210 TRACE( "(%p) ref=%d\n", This, ref );
211
212 if ( ref == 1 )
213 InterlockedIncrement( &This->numIfaces );
214
215 return ref;
216 }
217
218 static ULONG WINAPI IDirectPlayLobby2AImpl_AddRef(IDirectPlayLobby2A *iface)
219 {
220 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
221 ULONG ref = InterlockedIncrement( &This->ref2A );
222
223 TRACE( "(%p) ref2A=%d\n", This, ref );
224
225 if ( ref == 1 )
226 InterlockedIncrement( &This->numIfaces );
227
228 return ref;
229 }
230
231 static ULONG WINAPI IDirectPlayLobby2Impl_AddRef(IDirectPlayLobby2 *iface)
232 {
233 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
234 ULONG ref = InterlockedIncrement( &This->ref2 );
235
236 TRACE( "(%p) ref2=%d\n", This, ref );
237
238 if ( ref == 1 )
239 InterlockedIncrement( &This->numIfaces );
240
241 return ref;
242 }
243
244 static ULONG WINAPI IDirectPlayLobby3AImpl_AddRef(IDirectPlayLobby3A *iface)
245 {
246 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
247 ULONG ref = InterlockedIncrement( &This->ref3A );
248
249 TRACE( "(%p) ref3A=%d\n", This, ref );
250
251 if ( ref == 1 )
252 InterlockedIncrement( &This->numIfaces );
253
254 return ref;
255 }
256
257 static ULONG WINAPI IDirectPlayLobby3Impl_AddRef(IDirectPlayLobby3 *iface)
258 {
259 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
260 ULONG ref = InterlockedIncrement( &This->ref3 );
261
262 TRACE( "(%p) ref3=%d\n", This, ref );
263
264 if ( ref == 1 )
265 InterlockedIncrement( &This->numIfaces );
266
267 return ref;
268 }
269
270 static ULONG WINAPI IDirectPlayLobbyAImpl_Release( IDirectPlayLobbyA *iface )
271 {
272 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
273 ULONG ref = InterlockedDecrement( &This->refA );
274
275 TRACE( "(%p) refA=%d\n", This, ref );
276
277 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
278 dplobby_destroy( This );
279
280 return ref;
281 }
282
283 static ULONG WINAPI IDirectPlayLobbyImpl_Release( IDirectPlayLobby *iface )
284 {
285 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
286 ULONG ref = InterlockedDecrement( &This->ref );
287
288 TRACE( "(%p) ref=%d\n", This, ref );
289
290 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
291 dplobby_destroy( This );
292
293 return ref;
294 }
295
296 static ULONG WINAPI IDirectPlayLobby2AImpl_Release(IDirectPlayLobby2A *iface)
297 {
298 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
299 ULONG ref = InterlockedDecrement( &This->ref2A );
300
301 TRACE( "(%p) ref2A=%d\n", This, ref );
302
303 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
304 dplobby_destroy( This );
305
306 return ref;
307 }
308
309 static ULONG WINAPI IDirectPlayLobby2Impl_Release(IDirectPlayLobby2 *iface)
310 {
311 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
312 ULONG ref = InterlockedDecrement( &This->ref2 );
313
314 TRACE( "(%p) ref2=%d\n", This, ref );
315
316 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
317 dplobby_destroy( This );
318
319 return ref;
320 }
321
322 static ULONG WINAPI IDirectPlayLobby3AImpl_Release(IDirectPlayLobby3A *iface)
323 {
324 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
325 ULONG ref = InterlockedDecrement( &This->ref3A );
326
327 TRACE( "(%p) ref3A=%d\n", This, ref );
328
329 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
330 dplobby_destroy( This );
331
332 return ref;
333 }
334
335 static ULONG WINAPI IDirectPlayLobby3Impl_Release(IDirectPlayLobby3 *iface)
336 {
337 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
338 ULONG ref = InterlockedDecrement( &This->ref3 );
339
340 TRACE( "(%p) ref3=%d\n", This, ref );
341
342 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
343 dplobby_destroy( This );
344
345 return ref;
346 }
347
348
349 /********************************************************************
350 *
351 * Connects an application to the session specified by the DPLCONNECTION
352 * structure currently stored with the DirectPlayLobby object.
353 *
354 * Returns an IDirectPlay interface.
355 *
356 */
357 static HRESULT DPL_ConnectEx( IDirectPlayLobbyImpl *This, DWORD dwFlags, REFIID riid, void **lplpDP,
358 IUnknown* pUnk)
359 {
360 HRESULT hr;
361 DWORD dwOpenFlags = 0;
362 DWORD dwConnSize = 0;
363 LPDPLCONNECTION lpConn;
364
365 FIXME("(%p)->(0x%08x,%p,%p): semi stub\n", This, dwFlags, lplpDP, pUnk );
366
367 if( pUnk )
368 {
369 return DPERR_INVALIDPARAMS;
370 }
371
372 /* Backwards compatibility */
373 if( dwFlags == 0 )
374 {
375 dwFlags = DPCONNECT_RETURNSTATUS;
376 }
377
378 if ( ( hr = dplay_create( riid, lplpDP ) ) != DP_OK )
379 {
380 ERR( "error creating interface for %s:%s.\n",
381 debugstr_guid( riid ), DPLAYX_HresultToString( hr ) );
382 return hr;
383 }
384
385 /* FIXME: Is it safe/correct to use appID of 0? */
386 hr = IDirectPlayLobby_GetConnectionSettings( &This->IDirectPlayLobby3_iface,
387 0, NULL, &dwConnSize );
388 if( hr != DPERR_BUFFERTOOSMALL )
389 {
390 return hr;
391 }
392
393 lpConn = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwConnSize );
394
395 if( lpConn == NULL )
396 {
397 return DPERR_NOMEMORY;
398 }
399
400 /* FIXME: Is it safe/correct to use appID of 0? */
401 hr = IDirectPlayLobby_GetConnectionSettings( &This->IDirectPlayLobby3_iface,
402 0, lpConn, &dwConnSize );
403 if( FAILED( hr ) )
404 {
405 HeapFree( GetProcessHeap(), 0, lpConn );
406 return hr;
407 }
408
409 #if 0
410 /* - Need to call IDirectPlay::EnumConnections with the service provider to get that good information
411 * - Need to call CreateAddress to create the lpConnection param for IDirectPlay::InitializeConnection
412 * - Call IDirectPlay::InitializeConnection
413 */
414
415 /* Now initialize the Service Provider */
416 hr = IDirectPlayX_InitializeConnection( (*(LPDIRECTPLAY2*)lplpDP),
417 #endif
418
419
420 /* Setup flags to pass into DirectPlay::Open */
421 if( dwFlags & DPCONNECT_RETURNSTATUS )
422 {
423 dwOpenFlags |= DPOPEN_RETURNSTATUS;
424 }
425 dwOpenFlags |= lpConn->dwFlags;
426
427 hr = IDirectPlayX_Open( (*(LPDIRECTPLAY2*)lplpDP), lpConn->lpSessionDesc,
428 dwOpenFlags );
429
430 HeapFree( GetProcessHeap(), 0, lpConn );
431
432 return hr;
433 }
434
435 static HRESULT WINAPI IDirectPlayLobbyAImpl_Connect( IDirectPlayLobbyA *iface, DWORD flags,
436 IDirectPlay2A **dp, IUnknown *unk )
437 {
438 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
439 return IDirectPlayLobby_Connect( &This->IDirectPlayLobby3A_iface, flags, dp, unk );
440 }
441
442 static HRESULT WINAPI IDirectPlayLobbyImpl_Connect( IDirectPlayLobby *iface, DWORD flags,
443 IDirectPlay2A **dp, IUnknown *unk )
444 {
445 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
446 return IDirectPlayLobby_Connect( &This->IDirectPlayLobby3_iface, flags, dp, unk );
447 }
448
449 static HRESULT WINAPI IDirectPlayLobby2AImpl_Connect( IDirectPlayLobby2A *iface, DWORD flags,
450 IDirectPlay2A **dp, IUnknown *unk )
451 {
452 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
453 return IDirectPlayLobby_Connect( &This->IDirectPlayLobby3A_iface, flags, dp, unk );
454 }
455
456 static HRESULT WINAPI IDirectPlayLobby2Impl_Connect( IDirectPlayLobby2 *iface, DWORD flags,
457 IDirectPlay2A **dp, IUnknown *unk )
458 {
459 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
460 return IDirectPlayLobby_Connect( &This->IDirectPlayLobby3_iface, flags, dp, unk );
461 }
462
463 static HRESULT WINAPI IDirectPlayLobby3AImpl_Connect( IDirectPlayLobby3A *iface, DWORD flags,
464 IDirectPlay2A **dp, IUnknown *unk)
465 {
466 return IDirectPlayLobby_ConnectEx( iface, flags, &IID_IDirectPlay2A, (void**)dp, unk );
467 }
468
469 static HRESULT WINAPI IDirectPlayLobby3Impl_Connect( IDirectPlayLobby3 *iface, DWORD flags,
470 IDirectPlay2 **dp, IUnknown *unk)
471 {
472 return IDirectPlayLobby_ConnectEx( iface, flags, &IID_IDirectPlay2A, (void**)dp, unk );
473 }
474
475 /********************************************************************
476 *
477 * Creates a DirectPlay Address, given a service provider-specific network
478 * address.
479 * Returns an address contains the globally unique identifier
480 * (GUID) of the service provider and data that the service provider can
481 * interpret as a network address.
482 *
483 * NOTE: It appears that this method is supposed to be really really stupid
484 * with no error checking on the contents.
485 */
486 static HRESULT WINAPI IDirectPlayLobbyAImpl_CreateAddress( IDirectPlayLobbyA *iface, REFGUID sp,
487 REFGUID datatype, const void *data, DWORD datasize, void *address, DWORD *addrsize )
488 {
489 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
490 return IDirectPlayLobby_CreateAddress( &This->IDirectPlayLobby3A_iface, sp, datatype, data,
491 datasize, address, addrsize );
492 }
493
494 static HRESULT WINAPI IDirectPlayLobbyImpl_CreateAddress( IDirectPlayLobby *iface, REFGUID sp,
495 REFGUID datatype, const void *data, DWORD datasize, void *address, DWORD *addrsize )
496 {
497 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
498 return IDirectPlayLobby_CreateAddress( &This->IDirectPlayLobby3_iface, sp, datatype, data,
499 datasize, address, addrsize );
500 }
501
502 static HRESULT WINAPI IDirectPlayLobby2AImpl_CreateAddress( IDirectPlayLobby2A *iface, REFGUID sp,
503 REFGUID datatype, const void *data, DWORD datasize, void *address, DWORD *addrsize )
504 {
505 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
506 return IDirectPlayLobby_CreateAddress( &This->IDirectPlayLobby3A_iface, sp, datatype, data,
507 datasize, address, addrsize );
508 }
509
510 static HRESULT WINAPI IDirectPlayLobby2Impl_CreateAddress( IDirectPlayLobby2 *iface, REFGUID sp,
511 REFGUID datatype, const void *data, DWORD datasize, void *address, DWORD *addrsize )
512 {
513 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
514 return IDirectPlayLobby_CreateAddress( &This->IDirectPlayLobby3_iface, sp, datatype, data,
515 datasize, address, addrsize );
516 }
517
518 static HRESULT WINAPI IDirectPlayLobby3AImpl_CreateAddress( IDirectPlayLobby3A *iface,
519 REFGUID guidSP, REFGUID guidDataType, const void *lpData, DWORD dwDataSize, void *lpAddress,
520 DWORD *lpdwAddressSize )
521 {
522 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
523 lpAddress, lpdwAddressSize, TRUE );
524 }
525
526 static HRESULT WINAPI IDirectPlayLobby3Impl_CreateAddress( IDirectPlayLobby3 *iface, REFGUID guidSP,
527 REFGUID guidDataType, const void *lpData, DWORD dwDataSize, void *lpAddress,
528 DWORD *lpdwAddressSize )
529 {
530 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
531 lpAddress, lpdwAddressSize, FALSE );
532 }
533
534 static HRESULT DPL_CreateAddress(
535 REFGUID guidSP,
536 REFGUID guidDataType,
537 LPCVOID lpData,
538 DWORD dwDataSize,
539 LPVOID lpAddress,
540 LPDWORD lpdwAddressSize,
541 BOOL bAnsiInterface )
542 {
543 const DWORD dwNumAddElements = 2; /* Service Provide & address data type */
544 DPCOMPOUNDADDRESSELEMENT addressElements[ 2 /* dwNumAddElements */ ];
545
546 TRACE( "(%p)->(%p,%p,0x%08x,%p,%p,%d)\n", guidSP, guidDataType, lpData, dwDataSize,
547 lpAddress, lpdwAddressSize, bAnsiInterface );
548
549 addressElements[ 0 ].guidDataType = DPAID_ServiceProvider;
550 addressElements[ 0 ].dwDataSize = sizeof( GUID );
551 addressElements[ 0 ].lpData = (LPVOID)guidSP;
552
553 addressElements[ 1 ].guidDataType = *guidDataType;
554 addressElements[ 1 ].dwDataSize = dwDataSize;
555 addressElements[ 1 ].lpData = (LPVOID)lpData;
556
557 /* Call CreateCompoundAddress to cut down on code.
558 NOTE: We can do this because we don't support DPL 1 interfaces! */
559 return DPL_CreateCompoundAddress( addressElements, dwNumAddElements,
560 lpAddress, lpdwAddressSize, bAnsiInterface );
561 }
562
563
564
565 /********************************************************************
566 *
567 * Parses out chunks from the DirectPlay Address buffer by calling the
568 * given callback function, with lpContext, for each of the chunks.
569 *
570 */
571 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddress( IDirectPlayLobbyA *iface,
572 LPDPENUMADDRESSCALLBACK enumaddrcb, const void *address, DWORD size, void *context )
573 {
574 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
575 return IDirectPlayLobby_EnumAddress( &This->IDirectPlayLobby3A_iface, enumaddrcb, address, size,
576 context );
577 }
578
579 static HRESULT WINAPI IDirectPlayLobbyImpl_EnumAddress( IDirectPlayLobby *iface,
580 LPDPENUMADDRESSCALLBACK enumaddrcb, const void *address, DWORD size, void *context )
581 {
582 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
583 return IDirectPlayLobby_EnumAddress( &This->IDirectPlayLobby3_iface, enumaddrcb, address, size,
584 context );
585 }
586
587 static HRESULT WINAPI IDirectPlayLobby2AImpl_EnumAddress( IDirectPlayLobby2A *iface,
588 LPDPENUMADDRESSCALLBACK enumaddrcb, const void *address, DWORD size, void *context )
589 {
590 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
591 return IDirectPlayLobby_EnumAddress( &This->IDirectPlayLobby3A_iface, enumaddrcb, address, size,
592 context );
593 }
594
595 static HRESULT WINAPI IDirectPlayLobby2Impl_EnumAddress( IDirectPlayLobby2 *iface,
596 LPDPENUMADDRESSCALLBACK enumaddrcb, const void *address, DWORD size, void *context )
597 {
598 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
599 return IDirectPlayLobby_EnumAddress( &This->IDirectPlayLobby3_iface, enumaddrcb, address, size,
600 context );
601 }
602
603 static HRESULT WINAPI IDirectPlayLobby3AImpl_EnumAddress( IDirectPlayLobby3A *iface,
604 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, const void *lpAddress, DWORD dwAddressSize,
605 void *lpContext )
606 {
607 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
608
609 TRACE("(%p)->(%p,%p,0x%08x,%p)\n", This, lpEnumAddressCallback, lpAddress,
610 dwAddressSize, lpContext );
611
612 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
613 }
614
615 static HRESULT WINAPI IDirectPlayLobby3Impl_EnumAddress( IDirectPlayLobby3 *iface,
616 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, const void *lpAddress, DWORD dwAddressSize,
617 void *lpContext )
618 {
619 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
620
621 TRACE("(%p)->(%p,%p,0x%08x,%p)\n", This, lpEnumAddressCallback, lpAddress,
622 dwAddressSize, lpContext );
623
624 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
625 }
626
627 HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
628 DWORD dwAddressSize, LPVOID lpContext )
629 {
630 DWORD dwTotalSizeEnumerated = 0;
631
632 /* FIXME: First chunk is always the total size chunk - Should we report it? */
633
634 while ( dwTotalSizeEnumerated < dwAddressSize )
635 {
636 const DPADDRESS* lpElements = lpAddress;
637 DWORD dwSizeThisEnumeration;
638
639 /* Invoke the enum method. If false is returned, stop enumeration */
640 if ( !lpEnumAddressCallback( &lpElements->guidDataType,
641 lpElements->dwDataSize,
642 (const BYTE *)lpElements + sizeof( DPADDRESS ),
643 lpContext ) )
644 {
645 break;
646 }
647
648 dwSizeThisEnumeration = sizeof( DPADDRESS ) + lpElements->dwDataSize;
649 lpAddress = (const BYTE*) lpAddress + dwSizeThisEnumeration;
650 dwTotalSizeEnumerated += dwSizeThisEnumeration;
651 }
652
653 return DP_OK;
654 }
655
656 /********************************************************************
657 *
658 * Enumerates all the address types that a given service provider needs to
659 * build the DirectPlay Address.
660 *
661 */
662 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddressTypes( IDirectPlayLobbyA *iface,
663 LPDPLENUMADDRESSTYPESCALLBACK enumaddrtypecb, REFGUID sp, void *context, DWORD flags )
664 {
665 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
666 return IDirectPlayLobby_EnumAddressTypes( &This->IDirectPlayLobby3A_iface, enumaddrtypecb, sp,
667 context, flags );
668 }
669
670 static HRESULT WINAPI IDirectPlayLobbyImpl_EnumAddressTypes( IDirectPlayLobby *iface,
671 LPDPLENUMADDRESSTYPESCALLBACK enumaddrtypecb, REFGUID sp, void *context, DWORD flags )
672 {
673 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
674 return IDirectPlayLobby_EnumAddressTypes( &This->IDirectPlayLobby3_iface, enumaddrtypecb, sp,
675 context, flags );
676 }
677
678 static HRESULT WINAPI IDirectPlayLobby2AImpl_EnumAddressTypes( IDirectPlayLobby2A *iface,
679 LPDPLENUMADDRESSTYPESCALLBACK enumaddrtypecb, REFGUID sp, void *context, DWORD flags )
680 {
681 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
682 return IDirectPlayLobby_EnumAddressTypes( &This->IDirectPlayLobby3A_iface, enumaddrtypecb, sp,
683 context, flags );
684 }
685
686 static HRESULT WINAPI IDirectPlayLobby2Impl_EnumAddressTypes( IDirectPlayLobby2 *iface,
687 LPDPLENUMADDRESSTYPESCALLBACK enumaddrtypecb, REFGUID sp, void *context, DWORD flags )
688 {
689 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
690 return IDirectPlayLobby_EnumAddressTypes( &This->IDirectPlayLobby3_iface, enumaddrtypecb, sp,
691 context, flags );
692 }
693
694 static HRESULT WINAPI IDirectPlayLobby3AImpl_EnumAddressTypes( IDirectPlayLobby3A *iface,
695 LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback, REFGUID guidSP, void *lpContext,
696 DWORD dwFlags )
697 {
698 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
699
700 HKEY hkResult;
701 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Service Providers";
702 DWORD dwIndex, sizeOfSubKeyName=50;
703 char subKeyName[51];
704 FILETIME filetime;
705
706 TRACE(" (%p)->(%p,%p,%p,0x%08x)\n", This, lpEnumAddressTypeCallback, guidSP, lpContext, dwFlags );
707
708 if( dwFlags != 0 )
709 {
710 return DPERR_INVALIDPARAMS;
711 }
712
713 if( !lpEnumAddressTypeCallback )
714 {
715 return DPERR_INVALIDPARAMS;
716 }
717
718 if( guidSP == NULL )
719 {
720 return DPERR_INVALIDOBJECT;
721 }
722
723 /* Need to loop over the service providers in the registry */
724 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
725 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
726 {
727 /* Hmmm. Does this mean that there are no service providers? */
728 ERR(": no service providers?\n");
729 return DP_OK;
730 }
731
732 /* Traverse all the service providers we have available */
733 for( dwIndex=0;
734 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
735 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
736 ++dwIndex, sizeOfSubKeyName=50 )
737 {
738
739 HKEY hkServiceProvider, hkServiceProviderAt;
740 GUID serviceProviderGUID;
741 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
742 char atSubKey[51];
743 char returnBuffer[51];
744 WCHAR buff[51];
745 DWORD dwAtIndex;
746 LPCSTR atKey = "Address Types";
747 LPCSTR guidDataSubKey = "Guid";
748 FILETIME filetime;
749
750
751 TRACE(" this time through: %s\n", subKeyName );
752
753 /* Get a handle for this particular service provider */
754 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
755 &hkServiceProvider ) != ERROR_SUCCESS )
756 {
757 ERR(": what the heck is going on?\n" );
758 continue;
759 }
760
761 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
762 NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
763 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
764 {
765 ERR(": missing GUID registry data members\n" );
766 continue;
767 }
768
769 /* FIXME: Check return types to ensure we're interpreting data right */
770 MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff)/sizeof(WCHAR) );
771 CLSIDFromString( buff, &serviceProviderGUID );
772 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
773
774 /* Determine if this is the Service Provider that the user asked for */
775 if( !IsEqualGUID( &serviceProviderGUID, guidSP ) )
776 {
777 continue;
778 }
779
780 /* Get a handle for this particular service provider */
781 if( RegOpenKeyExA( hkServiceProvider, atKey, 0, KEY_READ,
782 &hkServiceProviderAt ) != ERROR_SUCCESS )
783 {
784 TRACE(": No Address Types registry data sub key/members\n" );
785 break;
786 }
787
788 /* Traverse all the address type we have available */
789 for( dwAtIndex=0;
790 RegEnumKeyExA( hkServiceProviderAt, dwAtIndex, atSubKey, &sizeOfSubKeyName,
791 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
792 ++dwAtIndex, sizeOfSubKeyName=50 )
793 {
794 TRACE( "Found Address Type GUID %s\n", atSubKey );
795
796 /* FIXME: Check return types to ensure we're interpreting data right */
797 MultiByteToWideChar( CP_ACP, 0, atSubKey, -1, buff, sizeof(buff)/sizeof(WCHAR) );
798 CLSIDFromString( buff, &serviceProviderGUID );
799 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
800
801 /* The enumeration will return FALSE if we are not to continue */
802 if( !lpEnumAddressTypeCallback( &serviceProviderGUID, lpContext, 0 ) )
803 {
804 WARN("lpEnumCallback returning FALSE\n" );
805 break; /* FIXME: This most likely has to break from the procedure...*/
806 }
807
808 }
809
810 /* We only enumerate address types for 1 GUID. We've found it, so quit looking */
811 break;
812 }
813
814 return DP_OK;
815 }
816
817 static HRESULT WINAPI IDirectPlayLobby3Impl_EnumAddressTypes( IDirectPlayLobby3 *iface,
818 LPDPLENUMADDRESSTYPESCALLBACK enumaddrtypecb, REFGUID sp, void *context, DWORD flags )
819 {
820 FIXME(":stub\n");
821 return DPERR_OUTOFMEMORY;
822 }
823
824 /********************************************************************
825 *
826 * Enumerates what applications are registered with DirectPlay by
827 * invoking the callback function with lpContext.
828 *
829 */
830 static HRESULT WINAPI IDirectPlayLobby3Impl_EnumLocalApplications( IDirectPlayLobby3 *iface,
831 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback, void *lpContext, DWORD dwFlags )
832 {
833 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
834
835 FIXME("(%p)->(%p,%p,0x%08x):stub\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
836
837 return DPERR_OUTOFMEMORY;
838 }
839
840 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumLocalApplications( IDirectPlayLobbyA *iface,
841 LPDPLENUMLOCALAPPLICATIONSCALLBACK enumlocalappcb, void *context, DWORD flags )
842 {
843 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
844 return IDirectPlayLobby_EnumLocalApplications( &This->IDirectPlayLobby3A_iface, enumlocalappcb,
845 context, flags );
846 }
847
848 static HRESULT WINAPI IDirectPlayLobbyImpl_EnumLocalApplications( IDirectPlayLobby *iface,
849 LPDPLENUMLOCALAPPLICATIONSCALLBACK enumlocalappcb, void *context, DWORD flags )
850 {
851 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
852 return IDirectPlayLobby_EnumLocalApplications( &This->IDirectPlayLobby3_iface, enumlocalappcb,
853 context, flags );
854 }
855
856 static HRESULT WINAPI IDirectPlayLobby2AImpl_EnumLocalApplications( IDirectPlayLobby2A *iface,
857 LPDPLENUMLOCALAPPLICATIONSCALLBACK enumlocalappcb, void *context, DWORD flags )
858 {
859 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
860 return IDirectPlayLobby_EnumLocalApplications( &This->IDirectPlayLobby3A_iface, enumlocalappcb,
861 context, flags );
862 }
863
864 static HRESULT WINAPI IDirectPlayLobby2Impl_EnumLocalApplications( IDirectPlayLobby2 *iface,
865 LPDPLENUMLOCALAPPLICATIONSCALLBACK enumlocalappcb, void *context, DWORD flags )
866 {
867 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
868 return IDirectPlayLobby_EnumLocalApplications( &This->IDirectPlayLobby3_iface, enumlocalappcb,
869 context, flags );
870 }
871
872 static HRESULT WINAPI IDirectPlayLobby3AImpl_EnumLocalApplications( IDirectPlayLobby3A *iface,
873 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback, void *lpContext, DWORD dwFlags )
874 {
875 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
876
877 HKEY hkResult;
878 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Applications";
879 LPCSTR guidDataSubKey = "Guid";
880 DWORD dwIndex, sizeOfSubKeyName=50;
881 char subKeyName[51];
882 FILETIME filetime;
883
884 TRACE("(%p)->(%p,%p,0x%08x)\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
885
886 if( dwFlags != 0 )
887 {
888 return DPERR_INVALIDPARAMS;
889 }
890
891 if( !lpEnumLocalAppCallback )
892 {
893 return DPERR_INVALIDPARAMS;
894 }
895
896 /* Need to loop over the service providers in the registry */
897 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
898 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
899 {
900 /* Hmmm. Does this mean that there are no service providers? */
901 ERR(": no service providers?\n");
902 return DP_OK;
903 }
904
905 /* Traverse all registered applications */
906 for( dwIndex=0;
907 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
908 ++dwIndex, sizeOfSubKeyName=50 )
909 {
910
911 HKEY hkServiceProvider;
912 GUID serviceProviderGUID;
913 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
914 char returnBuffer[51];
915 WCHAR buff[51];
916 DPLAPPINFO dplAppInfo;
917
918 TRACE(" this time through: %s\n", subKeyName );
919
920 /* Get a handle for this particular service provider */
921 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
922 &hkServiceProvider ) != ERROR_SUCCESS )
923 {
924 ERR(": what the heck is going on?\n" );
925 continue;
926 }
927
928 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
929 NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
930 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
931 {
932 ERR(": missing GUID registry data members\n" );
933 continue;
934 }
935
936 /* FIXME: Check return types to ensure we're interpreting data right */
937 MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff)/sizeof(WCHAR) );
938 CLSIDFromString( buff, &serviceProviderGUID );
939 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
940
941 dplAppInfo.dwSize = sizeof( dplAppInfo );
942 dplAppInfo.guidApplication = serviceProviderGUID;
943 dplAppInfo.u.lpszAppNameA = subKeyName;
944
945 EnterCriticalSection( &This->lock );
946
947 memcpy( &This->cbkeyhack, &hkServiceProvider, sizeof( hkServiceProvider ) );
948
949 if( !lpEnumLocalAppCallback( &dplAppInfo, lpContext, dwFlags ) )
950 {
951 LeaveCriticalSection( &This->lock );
952 break;
953 }
954
955 LeaveCriticalSection( &This->lock );
956 }
957
958 return DP_OK;
959 }
960
961 /********************************************************************
962 *
963 * Retrieves the DPLCONNECTION structure that contains all the information
964 * needed to start and connect an application. This was generated using
965 * either the RunApplication or SetConnectionSettings methods.
966 *
967 * NOTES: If lpData is NULL then just return lpdwDataSize. This allows
968 * the data structure to be allocated by our caller which can then
969 * call this procedure/method again with a valid data pointer.
970 */
971 static HRESULT WINAPI IDirectPlayLobbyAImpl_GetConnectionSettings( IDirectPlayLobbyA *iface,
972 DWORD appid, void *data, DWORD *size )
973 {
974 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
975 return IDirectPlayLobby_GetConnectionSettings( &This->IDirectPlayLobby3A_iface, appid, data,
976 size );
977 }
978
979 static HRESULT WINAPI IDirectPlayLobbyImpl_GetConnectionSettings( IDirectPlayLobby *iface,
980 DWORD appid, void *data, DWORD *size )
981 {
982 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
983 return IDirectPlayLobby_GetConnectionSettings( &This->IDirectPlayLobby3_iface, appid, data,
984 size );
985 }
986
987 static HRESULT WINAPI IDirectPlayLobby2AImpl_GetConnectionSettings( IDirectPlayLobby2A *iface,
988 DWORD appid, void *data, DWORD *size )
989 {
990 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
991 return IDirectPlayLobby_GetConnectionSettings( &This->IDirectPlayLobby3A_iface, appid, data,
992 size );
993 }
994
995 static HRESULT WINAPI IDirectPlayLobby2Impl_GetConnectionSettings( IDirectPlayLobby2 *iface,
996 DWORD appid, void *data, DWORD *size )
997 {
998 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
999 return IDirectPlayLobby_GetConnectionSettings( &This->IDirectPlayLobby3_iface, appid, data,
1000 size );
1001 }
1002
1003 static HRESULT WINAPI IDirectPlayLobby3AImpl_GetConnectionSettings( IDirectPlayLobby3A *iface,
1004 DWORD dwAppID, void *lpData, DWORD *lpdwDataSize )
1005 {
1006 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
1007 HRESULT hr;
1008
1009 TRACE("(%p)->(0x%08x,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
1010
1011 EnterCriticalSection( &This->lock );
1012
1013 hr = DPLAYX_GetConnectionSettingsA( dwAppID,
1014 lpData,
1015 lpdwDataSize
1016 );
1017
1018 LeaveCriticalSection( &This->lock );
1019
1020 return hr;
1021 }
1022
1023 static HRESULT WINAPI IDirectPlayLobby3Impl_GetConnectionSettings( IDirectPlayLobby3 *iface,
1024 DWORD dwAppID, void *lpData, DWORD *lpdwDataSize )
1025 {
1026 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
1027 HRESULT hr;
1028
1029 TRACE("(%p)->(0x%08x,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
1030
1031 EnterCriticalSection( &This->lock );
1032
1033 hr = DPLAYX_GetConnectionSettingsW( dwAppID,
1034 lpData,
1035 lpdwDataSize
1036 );
1037
1038 LeaveCriticalSection( &This->lock );
1039
1040 return hr;
1041 }
1042
1043 /********************************************************************
1044 *
1045 * Retrieves the message sent between a lobby client and a DirectPlay
1046 * application. All messages are queued until received.
1047 *
1048 */
1049 static HRESULT WINAPI IDirectPlayLobbyAImpl_ReceiveLobbyMessage( IDirectPlayLobbyA *iface,
1050 DWORD flags, DWORD appid, DWORD *msgflags, void *data, DWORD *size )
1051 {
1052 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
1053 return IDirectPlayLobby_ReceiveLobbyMessage( &This->IDirectPlayLobby3A_iface, flags, appid,
1054 msgflags, data, size );
1055 }
1056
1057 static HRESULT WINAPI IDirectPlayLobbyImpl_ReceiveLobbyMessage( IDirectPlayLobby *iface,
1058 DWORD flags, DWORD appid, DWORD *msgflags, void *data, DWORD *size )
1059 {
1060 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
1061 return IDirectPlayLobby_ReceiveLobbyMessage( &This->IDirectPlayLobby3_iface, flags, appid,
1062 msgflags, data, size );
1063 }
1064
1065 static HRESULT WINAPI IDirectPlayLobby2AImpl_ReceiveLobbyMessage( IDirectPlayLobby2A *iface,
1066 DWORD flags, DWORD appid, DWORD *msgflags, void *data, DWORD *size )
1067 {
1068 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
1069 return IDirectPlayLobby_ReceiveLobbyMessage( &This->IDirectPlayLobby3A_iface, flags, appid,
1070 msgflags, data, size );
1071 }
1072
1073 static HRESULT WINAPI IDirectPlayLobby2Impl_ReceiveLobbyMessage( IDirectPlayLobby2 *iface,
1074 DWORD flags, DWORD appid, DWORD *msgflags, void *data, DWORD *size )
1075 {
1076 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
1077 return IDirectPlayLobby_ReceiveLobbyMessage( &This->IDirectPlayLobby3_iface, flags, appid,
1078 msgflags, data, size );
1079 }
1080
1081 static HRESULT WINAPI IDirectPlayLobby3AImpl_ReceiveLobbyMessage( IDirectPlayLobby3A *iface,
1082 DWORD dwFlags, DWORD dwAppID, DWORD *lpdwMessageFlags, void *lpData,
1083 DWORD *lpdwDataSize )
1084 {
1085 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
1086 FIXME(":stub %p %08x %08x %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1087 lpdwDataSize );
1088 return DPERR_OUTOFMEMORY;
1089 }
1090
1091 static HRESULT WINAPI IDirectPlayLobby3Impl_ReceiveLobbyMessage( IDirectPlayLobby3 *iface,
1092 DWORD dwFlags, DWORD dwAppID, DWORD *lpdwMessageFlags, void *lpData,
1093 DWORD *lpdwDataSize )
1094 {
1095 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
1096 FIXME(":stub %p %08x %08x %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1097 lpdwDataSize );
1098 return DPERR_OUTOFMEMORY;
1099 }
1100
1101 typedef struct tagRunApplicationEnumStruct
1102 {
1103 IDirectPlayLobbyImpl *This;
1104
1105 GUID appGUID;
1106 LPSTR lpszPath;
1107 LPSTR lpszFileName;
1108 LPSTR lpszCommandLine;
1109 LPSTR lpszCurrentDirectory;
1110 } RunApplicationEnumStruct, *lpRunApplicationEnumStruct;
1111
1112 /* To be called by RunApplication to find how to invoke the function */
1113 static BOOL CALLBACK RunApplicationA_EnumLocalApplications
1114 ( LPCDPLAPPINFO lpAppInfo,
1115 LPVOID lpContext,
1116 DWORD dwFlags )
1117 {
1118 lpRunApplicationEnumStruct lpData = (lpRunApplicationEnumStruct)lpContext;
1119
1120 if( IsEqualGUID( &lpAppInfo->guidApplication, &lpData->appGUID ) )
1121 {
1122 char returnBuffer[200];
1123 DWORD returnType, sizeOfReturnBuffer;
1124 LPCSTR clSubKey = "CommandLine";
1125 LPCSTR cdSubKey = "CurrentDirectory";
1126 LPCSTR fileSubKey = "File";
1127 LPCSTR pathSubKey = "Path";
1128
1129 /* FIXME: Lazy man hack - dplay struct has the present reg key saved */
1130
1131 sizeOfReturnBuffer = 200;
1132
1133 /* Get all the appropriate data from the registry */
1134 if( RegQueryValueExA( lpData->This->cbkeyhack, clSubKey,
1135 NULL, &returnType, (LPBYTE)returnBuffer,
1136 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1137 {
1138 ERR( ": missing CommandLine registry data member\n" );
1139 }
1140 else
1141 {
1142 if ((lpData->lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1143 strcpy( lpData->lpszCommandLine, returnBuffer );
1144 }
1145
1146 sizeOfReturnBuffer = 200;
1147
1148 if( RegQueryValueExA( lpData->This->cbkeyhack, cdSubKey,
1149 NULL, &returnType, (LPBYTE)returnBuffer,
1150 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1151 {
1152 ERR( ": missing CurrentDirectory registry data member\n" );
1153 }
1154 else
1155 {
1156 if ((lpData->lpszCurrentDirectory = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1157 strcpy( lpData->lpszCurrentDirectory, returnBuffer );
1158 }
1159
1160 sizeOfReturnBuffer = 200;
1161
1162 if( RegQueryValueExA( lpData->This->cbkeyhack, fileSubKey,
1163 NULL, &returnType, (LPBYTE)returnBuffer,
1164 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1165 {
1166 ERR( ": missing File registry data member\n" );
1167 }
1168 else
1169 {
1170 if ((lpData->lpszFileName = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1171 strcpy( lpData->lpszFileName, returnBuffer );
1172 }
1173
1174 sizeOfReturnBuffer = 200;
1175
1176 if( RegQueryValueExA( lpData->This->cbkeyhack, pathSubKey,
1177 NULL, &returnType, (LPBYTE)returnBuffer,
1178 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1179 {
1180 ERR( ": missing Path registry data member\n" );
1181 }
1182 else
1183 {
1184 if ((lpData->lpszPath = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1185 strcpy( lpData->lpszPath, returnBuffer );
1186 }
1187
1188 return FALSE; /* No need to keep going as we found what we wanted */
1189 }
1190
1191 return TRUE; /* Keep enumerating, haven't found the application yet */
1192 }
1193
1194 static BOOL DPL_CreateAndSetLobbyHandles( DWORD dwDestProcessId, HANDLE hDestProcess,
1195 LPHANDLE lphStart, LPHANDLE lphDeath,
1196 LPHANDLE lphRead )
1197 {
1198 /* These are the handles for the created process */
1199 HANDLE hAppStart = 0, hAppDeath = 0, hAppRead = 0;
1200 SECURITY_ATTRIBUTES s_attrib;
1201
1202 s_attrib.nLength = sizeof( s_attrib );
1203 s_attrib.lpSecurityDescriptor = NULL;
1204 s_attrib.bInheritHandle = TRUE;
1205
1206 *lphStart = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
1207 *lphDeath = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
1208 *lphRead = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
1209
1210 if( ( !DuplicateHandle( GetCurrentProcess(), *lphStart,
1211 hDestProcess, &hAppStart,
1212 0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1213 ( !DuplicateHandle( GetCurrentProcess(), *lphDeath,
1214 hDestProcess, &hAppDeath,
1215 0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1216 ( !DuplicateHandle( GetCurrentProcess(), *lphRead,
1217 hDestProcess, &hAppRead,
1218 0, FALSE, DUPLICATE_SAME_ACCESS ) )
1219 )
1220 {
1221 if (*lphStart) { CloseHandle(*lphStart); *lphStart = 0; }
1222 if (*lphDeath) { CloseHandle(*lphDeath); *lphDeath = 0; }
1223 if (*lphRead) { CloseHandle(*lphRead); *lphRead = 0; }
1224 /* FIXME: Handle leak... */
1225 ERR( "Unable to dup handles\n" );
1226 return FALSE;
1227 }
1228
1229 if( !DPLAYX_SetLobbyHandles( dwDestProcessId,
1230 hAppStart, hAppDeath, hAppRead ) )
1231 {
1232 /* FIXME: Handle leak... */
1233 return FALSE;
1234 }
1235
1236 return TRUE;
1237 }
1238
1239
1240 /********************************************************************
1241 *
1242 * Starts an application and passes to it all the information to
1243 * connect to a session.
1244 *
1245 */
1246 static HRESULT WINAPI IDirectPlayLobbyAImpl_RunApplication( IDirectPlayLobbyA *iface, DWORD flags,
1247 DWORD *appid, DPLCONNECTION *conn, HANDLE event )
1248 {
1249 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
1250 return IDirectPlayLobby_RunApplication( &This->IDirectPlayLobby3A_iface, flags, appid, conn,
1251 event );
1252 }
1253
1254 static HRESULT WINAPI IDirectPlayLobbyImpl_RunApplication( IDirectPlayLobby *iface, DWORD flags,
1255 DWORD *appid, DPLCONNECTION *conn, HANDLE event )
1256 {
1257 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
1258 return IDirectPlayLobby_RunApplication( &This->IDirectPlayLobby3_iface, flags, appid, conn,
1259 event );
1260 }
1261
1262 static HRESULT WINAPI IDirectPlayLobby2AImpl_RunApplication( IDirectPlayLobby2A *iface, DWORD flags,
1263 DWORD *appid, DPLCONNECTION *conn, HANDLE event )
1264 {
1265 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
1266 return IDirectPlayLobby_RunApplication( &This->IDirectPlayLobby3A_iface, flags, appid, conn,
1267 event );
1268 }
1269
1270 static HRESULT WINAPI IDirectPlayLobby2Impl_RunApplication( IDirectPlayLobby2 *iface, DWORD flags,
1271 DWORD *appid, DPLCONNECTION *conn, HANDLE event )
1272 {
1273 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
1274 return IDirectPlayLobby_RunApplication( &This->IDirectPlayLobby3_iface, flags, appid, conn,
1275 event );
1276 }
1277
1278 static HRESULT WINAPI IDirectPlayLobby3AImpl_RunApplication( IDirectPlayLobby3A *iface,
1279 DWORD dwFlags, DWORD *lpdwAppID, DPLCONNECTION *lpConn, HANDLE hReceiveEvent )
1280 {
1281 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
1282 HRESULT hr;
1283 RunApplicationEnumStruct enumData;
1284 char temp[200];
1285 STARTUPINFOA startupInfo;
1286 PROCESS_INFORMATION newProcessInfo;
1287 LPSTR appName;
1288 DWORD dwSuspendCount;
1289 HANDLE hStart, hDeath, hSettingRead;
1290
1291 TRACE( "(%p)->(0x%08x,%p,%p,%p)\n",
1292 This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1293
1294 if( dwFlags != 0 )
1295 {
1296 return DPERR_INVALIDPARAMS;
1297 }
1298
1299 if( DPLAYX_AnyLobbiesWaitingForConnSettings() )
1300 {
1301 FIXME( "Waiting lobby not being handled correctly\n" );
1302 }
1303
1304 EnterCriticalSection( &This->lock );
1305
1306 ZeroMemory( &enumData, sizeof( enumData ) );
1307 enumData.This = This;
1308 enumData.appGUID = lpConn->lpSessionDesc->guidApplication;
1309
1310 /* Our callback function will fill up the enumData structure with all the information
1311 required to start a new process */
1312 IDirectPlayLobby_EnumLocalApplications( iface, RunApplicationA_EnumLocalApplications,
1313 (&enumData), 0 );
1314
1315 /* First the application name */
1316 strcpy( temp, enumData.lpszPath );
1317 strcat( temp, "\\" );
1318 strcat( temp, enumData.lpszFileName );
1319 HeapFree( GetProcessHeap(), 0, enumData.lpszPath );
1320 HeapFree( GetProcessHeap(), 0, enumData.lpszFileName );
1321 if ((appName = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 ))) strcpy( appName, temp );
1322
1323 /* Now the command line */
1324 strcat( temp, " " );
1325 strcat( temp, enumData.lpszCommandLine );
1326 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1327 if ((enumData.lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 )))
1328 strcpy( enumData.lpszCommandLine, temp );
1329
1330 ZeroMemory( &startupInfo, sizeof( startupInfo ) );
1331 startupInfo.cb = sizeof( startupInfo );
1332 /* FIXME: Should any fields be filled in? */
1333
1334 ZeroMemory( &newProcessInfo, sizeof( newProcessInfo ) );
1335
1336 if( !CreateProcessA( appName,
1337 enumData.lpszCommandLine,
1338 NULL,
1339 NULL,
1340 FALSE,
1341 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE | CREATE_SUSPENDED, /* Creation Flags */
1342 NULL,
1343 enumData.lpszCurrentDirectory,
1344 &startupInfo,
1345 &newProcessInfo
1346 )
1347 )
1348 {
1349 ERR( "Failed to create process for app %s\n", appName );
1350
1351 HeapFree( GetProcessHeap(), 0, appName );
1352 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1353 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1354
1355 LeaveCriticalSection( &This->lock );
1356 return DPERR_CANTCREATEPROCESS;
1357 }
1358
1359 HeapFree( GetProcessHeap(), 0, appName );
1360 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1361 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1362
1363 /* Reserve this global application id! */
1364 if( !DPLAYX_CreateLobbyApplication( newProcessInfo.dwProcessId ) )
1365 {
1366 ERR( "Unable to create global application data for 0x%08x\n",
1367 newProcessInfo.dwProcessId );
1368 }
1369
1370 hr = IDirectPlayLobby_SetConnectionSettings( iface, 0, newProcessInfo.dwProcessId, lpConn );
1371
1372 if( hr != DP_OK )
1373 {
1374 ERR( "SetConnectionSettings failure %s\n", DPLAYX_HresultToString( hr ) );
1375 LeaveCriticalSection( &This->lock );
1376 return hr;
1377 }
1378
1379 /* Setup the handles for application notification */
1380 DPL_CreateAndSetLobbyHandles( newProcessInfo.dwProcessId,
1381 newProcessInfo.hProcess,
1382 &hStart, &hDeath, &hSettingRead );
1383
1384 /* Setup the message thread ID */
1385 This->msgtid = CreateLobbyMessageReceptionThread( hReceiveEvent, hStart, hDeath, hSettingRead );
1386
1387 DPLAYX_SetLobbyMsgThreadId( newProcessInfo.dwProcessId, This->msgtid );
1388
1389 LeaveCriticalSection( &This->lock );
1390
1391 /* Everything seems to have been set correctly, update the dwAppID */
1392 *lpdwAppID = newProcessInfo.dwProcessId;
1393
1394 /* Unsuspend the process - should return the prev suspension count */
1395 if( ( dwSuspendCount = ResumeThread( newProcessInfo.hThread ) ) != 1 )
1396 {
1397 ERR( "ResumeThread failed with 0x%08x\n", dwSuspendCount );
1398 }
1399
1400 return DP_OK;
1401 }
1402
1403 static HRESULT WINAPI IDirectPlayLobby3Impl_RunApplication( IDirectPlayLobby3 *iface, DWORD dwFlags,
1404 DWORD *lpdwAppID, DPLCONNECTION *lpConn, HANDLE hReceiveEvent )
1405 {
1406 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
1407 FIXME( "(%p)->(0x%08x,%p,%p,%p):stub\n", This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1408 return DPERR_OUTOFMEMORY;
1409 }
1410
1411 /********************************************************************
1412 *
1413 * Sends a message between the application and the lobby client.
1414 * All messages are queued until received.
1415 *
1416 */
1417 static HRESULT WINAPI IDirectPlayLobbyAImpl_SendLobbyMessage( IDirectPlayLobbyA *iface, DWORD flags,
1418 DWORD appid, void *data, DWORD size )
1419 {
1420 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
1421 return IDirectPlayLobby_SendLobbyMessage( &This->IDirectPlayLobby3A_iface, flags, appid, data,
1422 size );
1423 }
1424
1425 static HRESULT WINAPI IDirectPlayLobbyImpl_SendLobbyMessage( IDirectPlayLobby *iface, DWORD flags,
1426 DWORD appid, void *data, DWORD size )
1427 {
1428 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
1429 return IDirectPlayLobby_SendLobbyMessage( &This->IDirectPlayLobby3_iface, flags, appid, data,
1430 size );
1431 }
1432
1433 static HRESULT WINAPI IDirectPlayLobby2AImpl_SendLobbyMessage( IDirectPlayLobby2A *iface,
1434 DWORD flags, DWORD appid, void *data, DWORD size )
1435 {
1436 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
1437 return IDirectPlayLobby_SendLobbyMessage( &This->IDirectPlayLobby3A_iface, flags, appid, data,
1438 size );
1439 }
1440
1441 static HRESULT WINAPI IDirectPlayLobby2Impl_SendLobbyMessage( IDirectPlayLobby2 *iface, DWORD flags,
1442 DWORD appid, void *data, DWORD size )
1443 {
1444 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
1445 return IDirectPlayLobby_SendLobbyMessage( &This->IDirectPlayLobby3_iface, flags, appid, data,
1446 size );
1447 }
1448
1449 static HRESULT WINAPI IDirectPlayLobby3AImpl_SendLobbyMessage( IDirectPlayLobby3A *iface,
1450 DWORD flags, DWORD appid, void *data, DWORD size )
1451 {
1452 FIXME(":stub\n");
1453 return DPERR_OUTOFMEMORY;
1454 }
1455
1456 static HRESULT WINAPI IDirectPlayLobby3Impl_SendLobbyMessage( IDirectPlayLobby3 *iface,
1457 DWORD flags, DWORD appid, void *data, DWORD size )
1458 {
1459 FIXME(":stub\n");
1460 return DPERR_OUTOFMEMORY;
1461 }
1462
1463 /********************************************************************
1464 *
1465 * Modifies the DPLCONNECTION structure to contain all information
1466 * needed to start and connect an application.
1467 *
1468 */
1469 static HRESULT WINAPI IDirectPlayLobby3Impl_SetConnectionSettings( IDirectPlayLobby3 *iface,
1470 DWORD dwFlags, DWORD dwAppID, DPLCONNECTION *lpConn )
1471 {
1472 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
1473 HRESULT hr;
1474
1475 TRACE("(%p)->(0x%08x,0x%08x,%p)\n", This, dwFlags, dwAppID, lpConn );
1476
1477 EnterCriticalSection( &This->lock );
1478
1479 hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1480
1481 /* FIXME: Don't think that this is supposed to fail, but the documentation
1482 is somewhat sketchy. I'll try creating a lobby application
1483 for this... */
1484 if( hr == DPERR_NOTLOBBIED )
1485 {
1486 FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
1487 if( dwAppID == 0 )
1488 {
1489 dwAppID = GetCurrentProcessId();
1490 }
1491 DPLAYX_CreateLobbyApplication( dwAppID );
1492 hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1493 }
1494
1495 LeaveCriticalSection( &This->lock );
1496
1497 return hr;
1498 }
1499
1500 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetConnectionSettings( IDirectPlayLobbyA *iface,
1501 DWORD flags, DWORD appid, DPLCONNECTION *conn )
1502 {
1503 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
1504 return IDirectPlayLobby_SetConnectionSettings( &This->IDirectPlayLobby3A_iface, flags,
1505 appid, conn );
1506 }
1507
1508 static HRESULT WINAPI IDirectPlayLobbyImpl_SetConnectionSettings( IDirectPlayLobby *iface,
1509 DWORD flags, DWORD appid, DPLCONNECTION *conn )
1510 {
1511 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
1512 return IDirectPlayLobby_SetConnectionSettings( &This->IDirectPlayLobby3_iface, flags,
1513 appid, conn );
1514 }
1515
1516 static HRESULT WINAPI IDirectPlayLobby2AImpl_SetConnectionSettings( IDirectPlayLobby2A *iface,
1517 DWORD flags, DWORD appid, DPLCONNECTION *conn )
1518 {
1519 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
1520 return IDirectPlayLobby_SetConnectionSettings( &This->IDirectPlayLobby3A_iface, flags,
1521 appid, conn );
1522 }
1523
1524 static HRESULT WINAPI IDirectPlayLobby2Impl_SetConnectionSettings( IDirectPlayLobby2 *iface,
1525 DWORD flags, DWORD appid, DPLCONNECTION *conn )
1526 {
1527 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
1528 return IDirectPlayLobby_SetConnectionSettings( &This->IDirectPlayLobby3_iface, flags,
1529 appid, conn );
1530 }
1531
1532 static HRESULT WINAPI IDirectPlayLobby3AImpl_SetConnectionSettings( IDirectPlayLobby3A *iface,
1533 DWORD dwFlags, DWORD dwAppID, DPLCONNECTION *lpConn )
1534 {
1535 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
1536 HRESULT hr;
1537
1538 TRACE("(%p)->(0x%08x,0x%08x,%p)\n", This, dwFlags, dwAppID, lpConn );
1539
1540 EnterCriticalSection( &This->lock );
1541
1542 hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1543
1544 /* FIXME: Don't think that this is supposed to fail, but the documentation
1545 is somewhat sketchy. I'll try creating a lobby application
1546 for this... */
1547 if( hr == DPERR_NOTLOBBIED )
1548 {
1549 FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
1550 dwAppID = GetCurrentProcessId();
1551 DPLAYX_CreateLobbyApplication( dwAppID );
1552 hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1553 }
1554
1555 LeaveCriticalSection( &This->lock );
1556
1557 return hr;
1558 }
1559
1560 /********************************************************************
1561 *
1562 * Registers an event that will be set when a lobby message is received.
1563 *
1564 */
1565 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetLobbyMessageEvent( IDirectPlayLobbyA *iface,
1566 DWORD flags, DWORD appid, HANDLE event )
1567 {
1568 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobbyA( iface );
1569 return IDirectPlayLobby_SetLobbyMessageEvent( &This->IDirectPlayLobby3A_iface, flags, appid,
1570 event );
1571 }
1572
1573 static HRESULT WINAPI IDirectPlayLobbyImpl_SetLobbyMessageEvent( IDirectPlayLobby *iface,
1574 DWORD flags, DWORD appid, HANDLE event )
1575 {
1576 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby( iface );
1577 return IDirectPlayLobby_SetLobbyMessageEvent( &This->IDirectPlayLobby3_iface, flags, appid,
1578 event );
1579 }
1580
1581 static HRESULT WINAPI IDirectPlayLobby2AImpl_SetLobbyMessageEvent( IDirectPlayLobby2A *iface,
1582 DWORD flags, DWORD appid, HANDLE event )
1583 {
1584 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
1585 return IDirectPlayLobby_SetLobbyMessageEvent( &This->IDirectPlayLobby3A_iface, flags, appid,
1586 event );
1587 }
1588
1589 static HRESULT WINAPI IDirectPlayLobby2Impl_SetLobbyMessageEvent( IDirectPlayLobby2 *iface,
1590 DWORD flags, DWORD appid, HANDLE event )
1591 {
1592 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
1593 return IDirectPlayLobby_SetLobbyMessageEvent( &This->IDirectPlayLobby3_iface, flags, appid,
1594 event );
1595 }
1596
1597 static HRESULT WINAPI IDirectPlayLobby3AImpl_SetLobbyMessageEvent( IDirectPlayLobby3A *iface,
1598 DWORD flags, DWORD appid, HANDLE event )
1599 {
1600 FIXME(":stub\n");
1601 return DPERR_OUTOFMEMORY;
1602 }
1603
1604 static HRESULT WINAPI IDirectPlayLobby3Impl_SetLobbyMessageEvent( IDirectPlayLobby3 *iface,
1605 DWORD flags, DWORD appid, HANDLE event )
1606 {
1607 FIXME(":stub\n");
1608 return DPERR_OUTOFMEMORY;
1609 }
1610
1611
1612 /* DPL 2 methods */
1613 static HRESULT WINAPI IDirectPlayLobby2AImpl_CreateCompoundAddress( IDirectPlayLobby2A *iface,
1614 const DPCOMPOUNDADDRESSELEMENT *elements, DWORD count, void *address, DWORD *size )
1615 {
1616 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2A( iface );
1617 return IDirectPlayLobby_CreateCompoundAddress( &This->IDirectPlayLobby3A_iface, elements,
1618 count, address, size );
1619 }
1620
1621 static HRESULT WINAPI IDirectPlayLobby2Impl_CreateCompoundAddress( IDirectPlayLobby2 *iface,
1622 const DPCOMPOUNDADDRESSELEMENT *elements, DWORD count, void *address, DWORD *size )
1623 {
1624 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby2( iface );
1625 return IDirectPlayLobby_CreateCompoundAddress( &This->IDirectPlayLobby3_iface, elements,
1626 count, address, size );
1627 }
1628
1629 static HRESULT WINAPI IDirectPlayLobby3Impl_CreateCompoundAddress( IDirectPlayLobby3 *iface,
1630 const DPCOMPOUNDADDRESSELEMENT *lpElements, DWORD dwElementCount, void *lpAddress,
1631 DWORD *lpdwAddressSize )
1632 {
1633 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, FALSE );
1634 }
1635
1636 static HRESULT WINAPI IDirectPlayLobby3AImpl_CreateCompoundAddress( IDirectPlayLobby3A *iface,
1637 const DPCOMPOUNDADDRESSELEMENT *lpElements, DWORD dwElementCount, void *lpAddress,
1638 DWORD *lpdwAddressSize )
1639 {
1640 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, TRUE );
1641 }
1642
1643 HRESULT DPL_CreateCompoundAddress
1644 ( LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1645 DWORD dwElementCount,
1646 LPVOID lpAddress,
1647 LPDWORD lpdwAddressSize,
1648 BOOL bAnsiInterface )
1649 {
1650 DWORD dwSizeRequired = 0;
1651 DWORD dwElements;
1652 LPCDPCOMPOUNDADDRESSELEMENT lpOrigElements = lpElements;
1653
1654 TRACE("(%p,0x%08x,%p,%p)\n", lpElements, dwElementCount, lpAddress, lpdwAddressSize );
1655
1656 /* Parameter check */
1657 if( ( lpElements == NULL ) ||
1658 ( dwElementCount == 0 ) /* FIXME: Not sure if this is a failure case */
1659 )
1660 {
1661 return DPERR_INVALIDPARAMS;
1662 }
1663
1664 /* Add the total size chunk */
1665 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DWORD );
1666
1667 /* Calculate the size of the buffer required */
1668 for ( dwElements = dwElementCount; dwElements > 0; --dwElements, ++lpElements )
1669 {
1670 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1671 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1672 )
1673 {
1674 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( GUID );
1675 }
1676 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1677 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1678 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1679 )
1680 {
1681 if( !bAnsiInterface )
1682 {
1683 ERR( "Ansi GUIDs used for unicode interface\n" );
1684 return DPERR_INVALIDFLAGS;
1685 }
1686
1687 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize;
1688 }
1689 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1690 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1691 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1692 )
1693 {
1694 if( bAnsiInterface )
1695 {
1696 ERR( "Unicode GUIDs used for ansi interface\n" );
1697 return DPERR_INVALIDFLAGS;
1698 }
1699
1700 FIXME( "Right size for unicode interface?\n" );
1701 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize * sizeof( WCHAR );
1702 }
1703 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1704 {
1705 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( WORD );
1706 }
1707 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1708 {
1709 FIXME( "Right size for unicode interface?\n" );
1710 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DPCOMPORTADDRESS ); /* FIXME: Right size? */
1711 }
1712 else
1713 {
1714 ERR( "Unknown GUID %s\n", debugstr_guid(&lpElements->guidDataType) );
1715 return DPERR_INVALIDFLAGS;
1716 }
1717 }
1718
1719 /* The user wants to know how big a buffer to allocate for us */
1720 if( ( lpAddress == NULL ) ||
1721 ( *lpdwAddressSize < dwSizeRequired )
1722 )
1723 {
1724 *lpdwAddressSize = dwSizeRequired;
1725 return DPERR_BUFFERTOOSMALL;
1726 }
1727
1728 /* Add the total size chunk */
1729 {
1730 LPDPADDRESS lpdpAddress = lpAddress;
1731
1732 lpdpAddress->guidDataType = DPAID_TotalSize;
1733 lpdpAddress->dwDataSize = sizeof( DWORD );
1734 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1735
1736 *(LPDWORD)lpAddress = dwSizeRequired;
1737 lpAddress = (char *) lpAddress + sizeof( DWORD );
1738 }
1739
1740 /* Calculate the size of the buffer required */
1741 for( dwElements = dwElementCount, lpElements = lpOrigElements;
1742 dwElements > 0;
1743 --dwElements, ++lpElements )
1744 {
1745 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1746 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1747 )
1748 {
1749 LPDPADDRESS lpdpAddress = lpAddress;
1750
1751 lpdpAddress->guidDataType = lpElements->guidDataType;
1752 lpdpAddress->dwDataSize = sizeof( GUID );
1753 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1754
1755 CopyMemory( lpAddress, lpElements->lpData, sizeof( GUID ) );
1756 lpAddress = (char *) lpAddress + sizeof( GUID );
1757 }
1758 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1759 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1760 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1761 )
1762 {
1763 LPDPADDRESS lpdpAddress = lpAddress;
1764
1765 lpdpAddress->guidDataType = lpElements->guidDataType;
1766 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1767 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1768
1769 lstrcpynA( lpAddress, lpElements->lpData, lpElements->dwDataSize );
1770 lpAddress = (char *) lpAddress + lpElements->dwDataSize;
1771 }
1772 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1773 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1774 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1775 )
1776 {
1777 LPDPADDRESS lpdpAddress = lpAddress;
1778
1779 lpdpAddress->guidDataType = lpElements->guidDataType;
1780 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1781 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1782
1783 lstrcpynW( lpAddress, lpElements->lpData, lpElements->dwDataSize );
1784 lpAddress = (char *) lpAddress + lpElements->dwDataSize * sizeof( WCHAR );
1785 }
1786 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1787 {
1788 LPDPADDRESS lpdpAddress = lpAddress;
1789
1790 lpdpAddress->guidDataType = lpElements->guidDataType;
1791 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1792 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1793
1794 *((LPWORD)lpAddress) = *((LPWORD)lpElements->lpData);
1795 lpAddress = (char *) lpAddress + sizeof( WORD );
1796 }
1797 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1798 {
1799 LPDPADDRESS lpdpAddress = lpAddress;
1800
1801 lpdpAddress->guidDataType = lpElements->guidDataType;
1802 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1803 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1804
1805 CopyMemory( lpAddress, lpElements->lpData, sizeof( DPADDRESS ) );
1806 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1807 }
1808 }
1809
1810 return DP_OK;
1811 }
1812
1813 /* DPL 3 methods */
1814
1815 static HRESULT WINAPI IDirectPlayLobby3Impl_ConnectEx( IDirectPlayLobby3 *iface, DWORD dwFlags,
1816 REFIID riid, LPVOID* lplpDP, IUnknown* pUnk )
1817 {
1818 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3( iface );
1819 return DPL_ConnectEx( This, dwFlags, riid, lplpDP, pUnk );
1820 }
1821
1822 static HRESULT WINAPI IDirectPlayLobby3AImpl_ConnectEx( IDirectPlayLobby3A *iface, DWORD dwFlags,
1823 REFIID riid, void **lplpDP, IUnknown *pUnk )
1824 {
1825 IDirectPlayLobbyImpl *This = impl_from_IDirectPlayLobby3A( iface );
1826 return DPL_ConnectEx( This, dwFlags, riid, lplpDP, pUnk );
1827 }
1828
1829 static HRESULT WINAPI IDirectPlayLobby3Impl_RegisterApplication( IDirectPlayLobby3 *iface,
1830 DWORD flags, DPAPPLICATIONDESC *appdesc )
1831 {
1832 FIXME(":stub\n");
1833 return DP_OK;
1834 }
1835
1836 static HRESULT WINAPI IDirectPlayLobby3AImpl_RegisterApplication( IDirectPlayLobby3A *iface,
1837 DWORD flags, DPAPPLICATIONDESC *appdesc )
1838 {
1839 FIXME(":stub\n");
1840 return DP_OK;
1841 }
1842
1843 static HRESULT WINAPI IDirectPlayLobby3Impl_UnregisterApplication( IDirectPlayLobby3 *iface,
1844 DWORD flags, REFGUID appdesc )
1845 {
1846 FIXME(":stub\n");
1847 return DP_OK;
1848 }
1849
1850 static HRESULT WINAPI IDirectPlayLobby3AImpl_UnregisterApplication( IDirectPlayLobby3A *iface,
1851 DWORD flags, REFGUID appdesc )
1852 {
1853 FIXME(":stub\n");
1854 return DP_OK;
1855 }
1856
1857 static HRESULT WINAPI IDirectPlayLobby3Impl_WaitForConnectionSettings( IDirectPlayLobby3 *iface,
1858 DWORD dwFlags )
1859 {
1860 HRESULT hr = DP_OK;
1861 BOOL bStartWait = !(dwFlags & DPLWAIT_CANCEL);
1862
1863 TRACE( "(%p)->(0x%08x)\n", iface, dwFlags );
1864
1865 if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
1866 {
1867 /* FIXME: What is the correct error return code? */
1868 hr = DPERR_NOTLOBBIED;
1869 }
1870
1871 return hr;
1872 }
1873
1874 static HRESULT WINAPI IDirectPlayLobby3AImpl_WaitForConnectionSettings( IDirectPlayLobby3A *iface,
1875 DWORD dwFlags )
1876 {
1877 HRESULT hr = DP_OK;
1878 BOOL bStartWait = !(dwFlags & DPLWAIT_CANCEL);
1879
1880 TRACE( "(%p)->(0x%08x)\n", iface, dwFlags );
1881
1882 if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
1883 {
1884 /* FIXME: What is the correct error return code? */
1885 hr = DPERR_NOTLOBBIED;
1886 }
1887
1888 return hr;
1889 }
1890
1891 static const IDirectPlayLobbyVtbl dplA_vt =
1892 {
1893 IDirectPlayLobbyAImpl_QueryInterface,
1894 IDirectPlayLobbyAImpl_AddRef,
1895 IDirectPlayLobbyAImpl_Release,
1896 IDirectPlayLobbyAImpl_Connect,
1897 IDirectPlayLobbyAImpl_CreateAddress,
1898 IDirectPlayLobbyAImpl_EnumAddress,
1899 IDirectPlayLobbyAImpl_EnumAddressTypes,
1900 IDirectPlayLobbyAImpl_EnumLocalApplications,
1901 IDirectPlayLobbyAImpl_GetConnectionSettings,
1902 IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1903 IDirectPlayLobbyAImpl_RunApplication,
1904 IDirectPlayLobbyAImpl_SendLobbyMessage,
1905 IDirectPlayLobbyAImpl_SetConnectionSettings,
1906 IDirectPlayLobbyAImpl_SetLobbyMessageEvent
1907 };
1908
1909 static const IDirectPlayLobbyVtbl dpl_vt =
1910 {
1911 IDirectPlayLobbyImpl_QueryInterface,
1912 IDirectPlayLobbyImpl_AddRef,
1913 IDirectPlayLobbyImpl_Release,
1914 IDirectPlayLobbyImpl_Connect,
1915 IDirectPlayLobbyImpl_CreateAddress,
1916 IDirectPlayLobbyImpl_EnumAddress,
1917 IDirectPlayLobbyImpl_EnumAddressTypes,
1918 IDirectPlayLobbyImpl_EnumLocalApplications,
1919 IDirectPlayLobbyImpl_GetConnectionSettings,
1920 IDirectPlayLobbyImpl_ReceiveLobbyMessage,
1921 IDirectPlayLobbyImpl_RunApplication,
1922 IDirectPlayLobbyImpl_SendLobbyMessage,
1923 IDirectPlayLobbyImpl_SetConnectionSettings,
1924 IDirectPlayLobbyImpl_SetLobbyMessageEvent
1925 };
1926
1927 static const IDirectPlayLobby2Vtbl dpl2A_vt =
1928 {
1929 IDirectPlayLobby2AImpl_QueryInterface,
1930 IDirectPlayLobby2AImpl_AddRef,
1931 IDirectPlayLobby2AImpl_Release,
1932 IDirectPlayLobby2AImpl_Connect,
1933 IDirectPlayLobby2AImpl_CreateAddress,
1934 IDirectPlayLobby2AImpl_EnumAddress,
1935 IDirectPlayLobby2AImpl_EnumAddressTypes,
1936 IDirectPlayLobby2AImpl_EnumLocalApplications,
1937 IDirectPlayLobby2AImpl_GetConnectionSettings,
1938 IDirectPlayLobby2AImpl_ReceiveLobbyMessage,
1939 IDirectPlayLobby2AImpl_RunApplication,
1940 IDirectPlayLobby2AImpl_SendLobbyMessage,
1941 IDirectPlayLobby2AImpl_SetConnectionSettings,
1942 IDirectPlayLobby2AImpl_SetLobbyMessageEvent,
1943 IDirectPlayLobby2AImpl_CreateCompoundAddress
1944 };
1945
1946 static const IDirectPlayLobby2Vtbl dpl2_vt =
1947 {
1948 IDirectPlayLobby2Impl_QueryInterface,
1949 IDirectPlayLobby2Impl_AddRef,
1950 IDirectPlayLobby2Impl_Release,
1951 IDirectPlayLobby2Impl_Connect,
1952 IDirectPlayLobby2Impl_CreateAddress,
1953 IDirectPlayLobby2Impl_EnumAddress,
1954 IDirectPlayLobby2Impl_EnumAddressTypes,
1955 IDirectPlayLobby2Impl_EnumLocalApplications,
1956 IDirectPlayLobby2Impl_GetConnectionSettings,
1957 IDirectPlayLobby2Impl_ReceiveLobbyMessage,
1958 IDirectPlayLobby2Impl_RunApplication,
1959 IDirectPlayLobby2Impl_SendLobbyMessage,
1960 IDirectPlayLobby2Impl_SetConnectionSettings,
1961 IDirectPlayLobby2Impl_SetLobbyMessageEvent,
1962 IDirectPlayLobby2Impl_CreateCompoundAddress
1963 };
1964
1965 static const IDirectPlayLobby3Vtbl dpl3A_vt =
1966 {
1967 IDirectPlayLobby3AImpl_QueryInterface,
1968 IDirectPlayLobby3AImpl_AddRef,
1969 IDirectPlayLobby3AImpl_Release,
1970 IDirectPlayLobby3AImpl_Connect,
1971 IDirectPlayLobby3AImpl_CreateAddress,
1972 IDirectPlayLobby3AImpl_EnumAddress,
1973 IDirectPlayLobby3AImpl_EnumAddressTypes,
1974 IDirectPlayLobby3AImpl_EnumLocalApplications,
1975 IDirectPlayLobby3AImpl_GetConnectionSettings,
1976 IDirectPlayLobby3AImpl_ReceiveLobbyMessage,
1977 IDirectPlayLobby3AImpl_RunApplication,
1978 IDirectPlayLobby3AImpl_SendLobbyMessage,
1979 IDirectPlayLobby3AImpl_SetConnectionSettings,
1980 IDirectPlayLobby3AImpl_SetLobbyMessageEvent,
1981 IDirectPlayLobby3AImpl_CreateCompoundAddress,
1982 IDirectPlayLobby3AImpl_ConnectEx,
1983 IDirectPlayLobby3AImpl_RegisterApplication,
1984 IDirectPlayLobby3AImpl_UnregisterApplication,
1985 IDirectPlayLobby3AImpl_WaitForConnectionSettings
1986 };
1987
1988 static const IDirectPlayLobby3Vtbl dpl3_vt =
1989 {
1990 IDirectPlayLobby3Impl_QueryInterface,
1991 IDirectPlayLobby3Impl_AddRef,
1992 IDirectPlayLobby3Impl_Release,
1993 IDirectPlayLobby3Impl_Connect,
1994 IDirectPlayLobby3Impl_CreateAddress,
1995 IDirectPlayLobby3Impl_EnumAddress,
1996 IDirectPlayLobby3Impl_EnumAddressTypes,
1997 IDirectPlayLobby3Impl_EnumLocalApplications,
1998 IDirectPlayLobby3Impl_GetConnectionSettings,
1999 IDirectPlayLobby3Impl_ReceiveLobbyMessage,
2000 IDirectPlayLobby3Impl_RunApplication,
2001 IDirectPlayLobby3Impl_SendLobbyMessage,
2002 IDirectPlayLobby3Impl_SetConnectionSettings,
2003 IDirectPlayLobby3Impl_SetLobbyMessageEvent,
2004 IDirectPlayLobby3Impl_CreateCompoundAddress,
2005 IDirectPlayLobby3Impl_ConnectEx,
2006 IDirectPlayLobby3Impl_RegisterApplication,
2007 IDirectPlayLobby3Impl_UnregisterApplication,
2008 IDirectPlayLobby3Impl_WaitForConnectionSettings
2009 };
2010
2011 HRESULT dplobby_create( REFIID riid, void **ppv )
2012 {
2013 IDirectPlayLobbyImpl *obj;
2014 HRESULT hr;
2015
2016 TRACE( "(%s, %p)\n", debugstr_guid( riid ), ppv );
2017
2018 *ppv = NULL;
2019 obj = HeapAlloc( GetProcessHeap(), 0, sizeof( *obj ) );
2020 if ( !obj )
2021 return DPERR_OUTOFMEMORY;
2022
2023 obj->IDirectPlayLobby_iface.lpVtbl = &dpl_vt;
2024 obj->IDirectPlayLobbyA_iface.lpVtbl = &dplA_vt;
2025 obj->IDirectPlayLobby2_iface.lpVtbl = &dpl2_vt;
2026 obj->IDirectPlayLobby2A_iface.lpVtbl = &dpl2A_vt;
2027 obj->IDirectPlayLobby3_iface.lpVtbl = &dpl3_vt;
2028 obj->IDirectPlayLobby3A_iface.lpVtbl = &dpl3A_vt;
2029 obj->numIfaces = 1;
2030 obj->msgtid = 0;
2031 obj->ref = 0;
2032 obj->refA = 0;
2033 obj->ref2 = 0;
2034 obj->ref2A = 0;
2035 obj->ref3 = 1;
2036 obj->ref3A = 0;
2037
2038 InitializeCriticalSection( &obj->lock );
2039 obj->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectPlayLobbyImpl.lock");
2040 DPQ_INIT( obj->msgs );
2041
2042 hr = IDirectPlayLobby_QueryInterface( &obj->IDirectPlayLobby3_iface, riid, ppv );
2043 IDirectPlayLobby_Release( &obj->IDirectPlayLobby3_iface );
2044
2045 return hr;
2046 }
2047
2048
2049
2050 /***************************************************************************
2051 * DirectPlayLobbyCreateA (DPLAYX.4)
2052 *
2053 */
2054 HRESULT WINAPI DirectPlayLobbyCreateA( GUID *lpGUIDDSP, IDirectPlayLobbyA **lplpDPL,
2055 IUnknown *lpUnk, void *lpData, DWORD dwDataSize )
2056 {
2057 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08x\n",
2058 lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);
2059
2060 /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
2061 * equal 0. These fields are mostly for future expansion.
2062 */
2063 if ( lpGUIDDSP || lpData || dwDataSize )
2064 {
2065 *lplpDPL = NULL;
2066 return DPERR_INVALIDPARAMS;
2067 }
2068
2069 if( lpUnk )
2070 {
2071 *lplpDPL = NULL;
2072 ERR("Bad parameters!\n" );
2073 return CLASS_E_NOAGGREGATION;
2074 }
2075
2076 return dplobby_create( &IID_IDirectPlayLobbyA, (void**)lplpDPL );
2077 }
2078
2079 /***************************************************************************
2080 * DirectPlayLobbyCreateW (DPLAYX.5)
2081 *
2082 */
2083 HRESULT WINAPI DirectPlayLobbyCreateW( GUID *lpGUIDDSP, IDirectPlayLobby **lplpDPL,
2084 IUnknown *lpUnk, void *lpData, DWORD dwDataSize )
2085 {
2086 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08x\n",
2087 lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);
2088
2089 /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
2090 * equal 0. These fields are mostly for future expansion.
2091 */
2092 if ( lpGUIDDSP || lpData || dwDataSize )
2093 {
2094 *lplpDPL = NULL;
2095 ERR("Bad parameters!\n" );
2096 return DPERR_INVALIDPARAMS;
2097 }
2098
2099 if( lpUnk )
2100 {
2101 *lplpDPL = NULL;
2102 ERR("Bad parameters!\n" );
2103 return CLASS_E_NOAGGREGATION;
2104 }
2105
2106 return dplobby_create( &IID_IDirectPlayLobby, (void**)lplpDPL );
2107 }