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