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