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