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