dplobby.c 61.5 KB
Newer Older
1 2
/* Direct Play Lobby 2 & 3 Implementation
 *
3
 * Copyright 1998,1999,2000 - Peter Hunnisett
4
 *
5 6 7 8 9 10 11 12 13 14 15 16
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18
 */
19
#include <stdarg.h>
20
#include <string.h>
21

22 23
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
24
#include "windef.h"
25
#include "winbase.h"
26 27
#include "winerror.h"
#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 35
#include "dplobby.h"
#include "dpinit.h"
36

37
WINE_DEFAULT_DEBUG_CHANNEL(dplay);
38

39 40 41 42 43 44 45 46 47
/*****************************************************************************
 * Predeclare the interface implementation structures
 */
typedef struct IDirectPlayLobbyImpl  IDirectPlayLobbyAImpl;
typedef struct IDirectPlayLobbyImpl  IDirectPlayLobbyWImpl;
typedef struct IDirectPlayLobby2Impl IDirectPlayLobby2AImpl;
typedef struct IDirectPlayLobby2Impl IDirectPlayLobby2WImpl;
typedef struct IDirectPlayLobby3Impl IDirectPlayLobby3AImpl;
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 )DECLSPEC_HIDDEN;
52

53
static HRESULT DPL_CreateAddress( REFGUID guidSP, REFGUID guidDataType, LPCVOID lpData, DWORD dwDataSize,
54 55 56
                           LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface );


57

58
extern HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
59 60
                                DWORD dwAddressSize, LPVOID lpContext );

61 62 63
static HRESULT DPL_ConnectEx( IDirectPlayLobbyAImpl* This,
                              DWORD dwFlags, REFIID riid,
                              LPVOID* lplpDP, IUnknown* pUnk );
64

65
static BOOL DPL_CreateAndSetLobbyHandles( DWORD dwDestProcessId, HANDLE hDestProcess,
66 67
                                   LPHANDLE lphStart, LPHANDLE lphDeath,
                                   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 77 78 79 80 81 82
 * object it was "released" with IUnknown interface being implemented in the 1 version.
 * Of course, with these new interfaces comes the data required to keep the state required
 * by these interfaces. So, basically, the pointers contain the data associated with
 * a release. If you use the data associated with release 3 in a release 2 object, you'll
 * get a run time trap, as that won't have any data.
 *
 */
83 84 85 86 87
struct DPLMSG
{
  DPQ_ENTRY( DPLMSG ) msgs;  /* Link to next queued message */
};
typedef struct DPLMSG* LPDPLMSG;
88 89 90

typedef struct tagDirectPlayLobbyIUnknownData
{
91
  LONG              ulObjRef;
92 93 94 95 96
  CRITICAL_SECTION  DPL_lock;
} DirectPlayLobbyIUnknownData;

typedef struct tagDirectPlayLobbyData
{
97
  HKEY  hkCallbackKeyHack;
98 99
  DWORD dwMsgThread;
  DPQ_HEAD( DPLMSG ) msgs;  /* List of messages received */
100 101 102 103 104 105 106 107 108 109 110 111
} DirectPlayLobbyData;

typedef struct tagDirectPlayLobby2Data
{
  BOOL dummy;
} DirectPlayLobby2Data;

typedef struct tagDirectPlayLobby3Data
{
  BOOL dummy;
} DirectPlayLobby3Data;

112
#define DPL_IMPL_FIELDS \
113
 LONG ulInterfaceRef; \
114 115 116 117
 DirectPlayLobbyIUnknownData*  unk; \
 DirectPlayLobbyData*          dpl; \
 DirectPlayLobby2Data*         dpl2; \
 DirectPlayLobby3Data*         dpl3;
118

119 120
struct IDirectPlayLobbyImpl
{
121
    const IDirectPlayLobbyVtbl *lpVtbl;
122
    DPL_IMPL_FIELDS
123
};
124

125 126
struct IDirectPlayLobby2Impl
{
127
    const IDirectPlayLobby2Vtbl *lpVtbl;
128
    DPL_IMPL_FIELDS
129
};
130

131 132
struct IDirectPlayLobby3Impl
{
133
    const IDirectPlayLobby3Vtbl *lpVtbl;
134
    DPL_IMPL_FIELDS
135 136 137
};

/* Forward declarations of virtual tables */
138 139 140
static const IDirectPlayLobbyVtbl  directPlayLobbyWVT;
static const IDirectPlayLobby2Vtbl directPlayLobby2WVT;
static const IDirectPlayLobby3Vtbl directPlayLobby3WVT;
141

142 143 144
static const IDirectPlayLobbyVtbl  directPlayLobbyAVT;
static const IDirectPlayLobby2Vtbl directPlayLobby2AVT;
static const IDirectPlayLobby3Vtbl directPlayLobby3AVT;
145

146
static BOOL DPL_CreateIUnknown( LPVOID lpDPL )
147
{
148
  IDirectPlayLobbyAImpl *This = 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
  This->unk->DPL_lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectPlayLobbyAImpl*->DirectPlayLobbyIUnknownData*->DPL_lock");
158

159
  return TRUE;
160 161
}

162
static BOOL DPL_DestroyIUnknown( LPVOID lpDPL )
163
{
164
  IDirectPlayLobbyAImpl *This = lpDPL;
165

166
  This->unk->DPL_lock.DebugInfo->Spare[0] = 0;
167 168
  DeleteCriticalSection( &This->unk->DPL_lock );
  HeapFree( GetProcessHeap(), 0, This->unk );
169 170 171 172

  return TRUE;
}

173
static BOOL DPL_CreateLobby1( LPVOID lpDPL )
174
{
175
  IDirectPlayLobbyAImpl *This = lpDPL;
176

177
  This->dpl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->dpl) ) );
178
  if ( This->dpl == NULL )
179 180 181 182
  {
    return FALSE;
  }

183
  DPQ_INIT( This->dpl->msgs );
184

185
  return TRUE;
186 187
}

188
static BOOL DPL_DestroyLobby1( LPVOID lpDPL )
189
{
190
  IDirectPlayLobbyAImpl *This = lpDPL;
191

192 193 194 195 196 197 198
  if( This->dpl->dwMsgThread )
  {
    FIXME( "Should kill the msg thread\n" );
  }

  DPQ_DELETEQ( This->dpl->msgs, msgs, LPDPLMSG, cbDeleteElemFromHeap );

199 200
  /* Delete the contents */
  HeapFree( GetProcessHeap(), 0, This->dpl );
201 202 203 204

  return TRUE;
}

205
static BOOL DPL_CreateLobby2( LPVOID lpDPL )
206
{
207
  IDirectPlayLobby2AImpl *This = lpDPL;
208

209
  This->dpl2 = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->dpl2) ) );
210
  if ( This->dpl2 == NULL )
211 212 213 214 215 216 217
  {
    return FALSE;
  }

  return TRUE;
}

218
static BOOL DPL_DestroyLobby2( LPVOID lpDPL )
219
{
220
  IDirectPlayLobby2AImpl *This = lpDPL;
221 222

  HeapFree( GetProcessHeap(), 0, This->dpl2 );
223 224 225 226

  return TRUE;
}

227
static BOOL DPL_CreateLobby3( LPVOID lpDPL )
228
{
229
  IDirectPlayLobby3AImpl *This = lpDPL;
230

231
  This->dpl3 = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->dpl3) ) );
232
  if ( This->dpl3 == NULL )
233 234 235 236 237 238 239
  {
    return FALSE;
  }

  return TRUE;
}

240
static BOOL DPL_DestroyLobby3( LPVOID lpDPL )
241
{
242
  IDirectPlayLobby3AImpl *This = lpDPL;
243 244

  HeapFree( GetProcessHeap(), 0, This->dpl3 );
245 246 247 248 249

  return TRUE;
}


250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
/* The COM interface for upversioning an interface
 * We've been given a GUID (riid) and we need to replace the present
 * interface with that of the requested interface.
 *
 * Snip from some Microsoft document:
 * There are four requirements for implementations of QueryInterface (In these
 * cases, "must succeed" means "must succeed barring catastrophic failure."):
 *
 *  * The set of interfaces accessible on an object through
 *    IUnknown::QueryInterface must be static, not dynamic. This means that
 *    if a call to QueryInterface for a pointer to a specified interface
 *    succeeds the first time, it must succeed again, and if it fails the
 *    first time, it must fail on all subsequent queries.
 *  * It must be symmetric ~W if a client holds a pointer to an interface on
 *    an object, and queries for that interface, the call must succeed.
 *  * It must be reflexive ~W if a client holding a pointer to one interface
 *    queries successfully for another, a query through the obtained pointer
 *    for the first interface must succeed.
 *  * It must be transitive ~W if a client holding a pointer to one interface
 *    queries successfully for a second, and through that pointer queries
 *    successfully for a third interface, a query for the first interface
 *    through the pointer for the third interface must succeed.
 */
HRESULT DPL_CreateInterface
274 275
         ( REFIID riid, LPVOID* ppvObj )
{
276
  TRACE( " for %s\n", debugstr_guid( riid ) );
277

278 279
  *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
                       sizeof( IDirectPlayLobbyWImpl ) );
280

281 282 283 284
  if( *ppvObj == NULL )
  {
    return DPERR_OUTOFMEMORY;
  }
285

286 287
  if( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
  {
288
    IDirectPlayLobbyWImpl *This = *ppvObj;
289
    This->lpVtbl = &directPlayLobbyWVT;
290 291 292
  }
  else if( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
  {
293
    IDirectPlayLobbyAImpl *This = *ppvObj;
294
    This->lpVtbl = &directPlayLobbyAVT;
295 296 297
  }
  else if( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
  {
298
    IDirectPlayLobby2WImpl *This = *ppvObj;
299
    This->lpVtbl = &directPlayLobby2WVT;
300 301 302
  }
  else if( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
  {
303
    IDirectPlayLobby2AImpl *This = *ppvObj;
304
    This->lpVtbl = &directPlayLobby2AVT;
305 306 307
  }
  else if( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
  {
308
    IDirectPlayLobby3WImpl *This = *ppvObj;
309
    This->lpVtbl = &directPlayLobby3WVT;
310 311 312
  }
  else if( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
  {
313
    IDirectPlayLobby3AImpl *This = *ppvObj;
314
    This->lpVtbl = &directPlayLobby3AVT;
315
  }
316 317 318
  else
  {
    /* Unsupported interface */
319
    HeapFree( GetProcessHeap(), 0, *ppvObj );
320 321
    *ppvObj = NULL;

322 323
    return E_NOINTERFACE;
  }
324

325 326 327 328 329 330
  /* Initialize it */
  if ( DPL_CreateIUnknown( *ppvObj ) &&
       DPL_CreateLobby1( *ppvObj ) &&
       DPL_CreateLobby2( *ppvObj ) &&
       DPL_CreateLobby3( *ppvObj )
     )
331
  {
332
    IDirectPlayLobby_AddRef( (LPDIRECTPLAYLOBBY)*ppvObj );
333 334 335
    return S_OK;
  }

336 337 338 339 340 341
  /* Initialize failed, destroy it */
  DPL_DestroyLobby3( *ppvObj );
  DPL_DestroyLobby2( *ppvObj );
  DPL_DestroyLobby1( *ppvObj );
  DPL_DestroyIUnknown( *ppvObj );
  HeapFree( GetProcessHeap(), 0, *ppvObj );
342

343 344
  *ppvObj = NULL;
  return DPERR_NOMEMORY;
345 346
}

347 348
static HRESULT WINAPI DPL_QueryInterface
( LPDIRECTPLAYLOBBYA iface,
349 350 351
  REFIID riid,
  LPVOID* ppvObj )
{
352
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
353
  TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
354

355
  *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
356
                       sizeof( *This ) );
357 358

  if( *ppvObj == NULL )
359
  {
360
    return DPERR_OUTOFMEMORY;
361 362
  }

363 364
  CopyMemory( *ppvObj, This, sizeof( *This )  );
  (*(IDirectPlayLobbyAImpl**)ppvObj)->ulInterfaceRef = 0;
365

366
  if( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
367
  {
368
    IDirectPlayLobbyWImpl *This = *ppvObj;
369
    This->lpVtbl = &directPlayLobbyWVT;
370
  }
371
  else if( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
372
  {
373
    IDirectPlayLobbyAImpl *This = *ppvObj;
374
    This->lpVtbl = &directPlayLobbyAVT;
375
  }
376
  else if( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
377
  {
378
    IDirectPlayLobby2WImpl *This = *ppvObj;
379
    This->lpVtbl = &directPlayLobby2WVT;
380
  }
381
  else if( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
382
  {
383
    IDirectPlayLobby2AImpl *This = *ppvObj;
384
    This->lpVtbl = &directPlayLobby2AVT;
385 386 387
  }
  else if( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
  {
388
    IDirectPlayLobby3WImpl *This = *ppvObj;
389
    This->lpVtbl = &directPlayLobby3WVT;
390 391 392
  }
  else if( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
  {
393
    IDirectPlayLobby3AImpl *This = *ppvObj;
394
    This->lpVtbl = &directPlayLobby3AVT;
395 396 397 398 399 400 401 402
  }
  else
  {
    /* Unsupported interface */
    HeapFree( GetProcessHeap(), 0, *ppvObj );
    *ppvObj = NULL;

    return E_NOINTERFACE;
403 404
  }

405
  IDirectPlayLobby_AddRef( (LPDIRECTPLAYLOBBY)*ppvObj );
406

407
  return S_OK;
408 409
}

410
/*
411 412 413
 * Simple procedure. Just increment the reference count to this
 * structure and return the new reference count.
 */
414
static ULONG WINAPI DPL_AddRef
415
( LPDIRECTPLAYLOBBY iface )
416
{
417
  ULONG ulInterfaceRefCount, ulObjRefCount;
418
  IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
419

420 421
  ulObjRefCount       = InterlockedIncrement( &This->unk->ulObjRef );
  ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );
422

423
  TRACE( "ref count incremented to %u:%u for %p\n",
424
         ulInterfaceRefCount, ulObjRefCount, This );
425

426
  return ulObjRefCount;
427 428 429 430 431 432 433
}

/*
 * Simple COM procedure. Decrease the reference count to this object.
 * If the object no longer has any reference counts, free up the associated
 * memory.
 */
434
static ULONG WINAPI DPL_Release
435 436
( LPDIRECTPLAYLOBBYA iface )
{
437
  ULONG ulInterfaceRefCount, ulObjRefCount;
438
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
439

440 441
  ulObjRefCount       = InterlockedDecrement( &This->unk->ulObjRef );
  ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );
442

443
  TRACE( "ref count decremented to %u:%u for %p\n",
444
         ulInterfaceRefCount, ulObjRefCount, This );
445 446

  /* Deallocate if this is the last reference to the object */
447
  if( ulObjRefCount == 0 )
448 449 450 451 452 453 454
  {
     DPL_DestroyLobby3( This );
     DPL_DestroyLobby2( This );
     DPL_DestroyLobby1( This );
     DPL_DestroyIUnknown( This );
  }

455 456 457 458 459 460
  if( ulInterfaceRefCount == 0 )
  {
    HeapFree( GetProcessHeap(), 0, This );
  }

  return ulInterfaceRefCount;
461 462 463 464
}


/********************************************************************
465
 *
466 467 468
 * Connects an application to the session specified by the DPLCONNECTION
 * structure currently stored with the DirectPlayLobby object.
 *
469
 * Returns an IDirectPlay interface.
470 471
 *
 */
472
static HRESULT DPL_ConnectEx
473
( IDirectPlayLobbyAImpl* This,
474
  DWORD     dwFlags,
475
  REFIID    riid,
476
  LPVOID*   lplpDP,
477 478
  IUnknown* pUnk)
{
479 480 481 482
  HRESULT         hr;
  DWORD           dwOpenFlags = 0;
  DWORD           dwConnSize = 0;
  LPDPLCONNECTION lpConn;
483

484
  FIXME("(%p)->(0x%08x,%p,%p): semi stub\n", This, dwFlags, lplpDP, pUnk );
485

486
  if( pUnk )
487 488 489 490
  {
     return DPERR_INVALIDPARAMS;
  }

491 492 493 494 495 496
  /* Backwards compatibility */
  if( dwFlags == 0 )
  {
    dwFlags = DPCONNECT_RETURNSTATUS;
  }

497
  /* Create the DirectPlay interface */
498
  if( ( hr = DP_CreateInterface( riid, lplpDP ) ) != DP_OK )
499
  {
500
     ERR( "error creating interface for %s:%s.\n",
501 502
          debugstr_guid( riid ), DPLAYX_HresultToString( hr ) );
     return hr;
503 504
  }

505
  /* FIXME: Is it safe/correct to use appID of 0? */
506 507
  hr = IDirectPlayLobby_GetConnectionSettings( (LPDIRECTPLAYLOBBY)This,
                                               0, NULL, &dwConnSize );
508 509 510 511
  if( hr != DPERR_BUFFERTOOSMALL )
  {
    return hr;
  }
512

513
  lpConn = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwConnSize );
514

515 516 517 518
  if( lpConn == NULL )
  {
    return DPERR_NOMEMORY;
  }
519

520
  /* FIXME: Is it safe/correct to use appID of 0? */
521
  hr = IDirectPlayLobby_GetConnectionSettings( (LPDIRECTPLAYLOBBY)This,
522 523 524
                                               0, lpConn, &dwConnSize );
  if( FAILED( hr ) )
  {
525
    HeapFree( GetProcessHeap(), 0, lpConn );
526 527 528
    return hr;
  }

529 530 531 532 533 534 535 536 537
#if 0
  /* - Need to call IDirectPlay::EnumConnections with the service provider to get that good information
   * - Need to call CreateAddress to create the lpConnection param for IDirectPlay::InitializeConnection
   * - Call IDirectPlay::InitializeConnection
   */

  /* Now initialize the Service Provider */
  hr = IDirectPlayX_InitializeConnection( (*(LPDIRECTPLAY2*)lplpDP),
#endif
538

539

540 541 542 543 544 545 546
  /* Setup flags to pass into DirectPlay::Open */
  if( dwFlags & DPCONNECT_RETURNSTATUS )
  {
    dwOpenFlags |= DPOPEN_RETURNSTATUS;
  }
  dwOpenFlags |= lpConn->dwFlags;

547
  hr = IDirectPlayX_Open( (*(LPDIRECTPLAY2*)lplpDP), lpConn->lpSessionDesc,
548 549 550 551 552 553 554 555 556 557 558 559 560
                          dwOpenFlags );

  HeapFree( GetProcessHeap(), 0, lpConn );

  return hr;
}

static HRESULT WINAPI IDirectPlayLobbyAImpl_Connect
( LPDIRECTPLAYLOBBYA iface,
  DWORD dwFlags,
  LPDIRECTPLAY2A* lplpDP,
  IUnknown* pUnk)
{
561
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
562
  return DPL_ConnectEx( This, dwFlags, &IID_IDirectPlay2A,
563
                        (LPVOID)lplpDP, pUnk );
564 565 566 567 568 569 570 571
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_Connect
( LPDIRECTPLAYLOBBY iface,
  DWORD dwFlags,
  LPDIRECTPLAY2* lplpDP,
  IUnknown* pUnk)
{
572
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface; /* Yes cast to A */
573
  return DPL_ConnectEx( This, dwFlags, &IID_IDirectPlay2,
574
                        (LPVOID)lplpDP, pUnk );
575 576 577 578 579
}

/********************************************************************
 *
 * Creates a DirectPlay Address, given a service provider-specific network
580
 * address.
581 582 583 584
 * Returns an address contains the globally unique identifier
 * (GUID) of the service provider and data that the service provider can
 * interpret as a network address.
 *
585 586
 * NOTE: It appears that this method is supposed to be really really stupid
 *       with no error checking on the contents.
587 588 589 590 591
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_CreateAddress
( LPDIRECTPLAYLOBBYA iface,
  REFGUID guidSP,
  REFGUID guidDataType,
592
  LPCVOID lpData,
593
  DWORD dwDataSize,
594
  LPVOID lpAddress,
595 596
  LPDWORD lpdwAddressSize )
{
597 598
  return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
                            lpAddress, lpdwAddressSize, TRUE );
599 600 601 602 603 604 605 606 607 608 609
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_CreateAddress
( LPDIRECTPLAYLOBBY iface,
  REFGUID guidSP,
  REFGUID guidDataType,
  LPCVOID lpData,
  DWORD dwDataSize,
  LPVOID lpAddress,
  LPDWORD lpdwAddressSize )
{
610 611 612 613
  return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
                            lpAddress, lpdwAddressSize, FALSE );
}

614
static HRESULT DPL_CreateAddress(
615 616 617 618 619 620 621 622
  REFGUID guidSP,
  REFGUID guidDataType,
  LPCVOID lpData,
  DWORD dwDataSize,
  LPVOID lpAddress,
  LPDWORD lpdwAddressSize,
  BOOL bAnsiInterface )
{
623
  const DWORD dwNumAddElements = 2; /* Service Provide & address data type */
624
  DPCOMPOUNDADDRESSELEMENT addressElements[ 2 /* dwNumAddElements */ ];
625

626
  TRACE( "(%p)->(%p,%p,0x%08x,%p,%p,%d)\n", guidSP, guidDataType, lpData, dwDataSize,
627
                                             lpAddress, lpdwAddressSize, bAnsiInterface );
628 629 630 631 632 633 634 635 636 637 638

  addressElements[ 0 ].guidDataType = DPAID_ServiceProvider;
  addressElements[ 0 ].dwDataSize = sizeof( GUID );
  addressElements[ 0 ].lpData = (LPVOID)guidSP;

  addressElements[ 1 ].guidDataType = *guidDataType;
  addressElements[ 1 ].dwDataSize = dwDataSize;
  addressElements[ 1 ].lpData = (LPVOID)lpData;

  /* Call CreateCompoundAddress to cut down on code.
     NOTE: We can do this because we don't support DPL 1 interfaces! */
639 640
  return DPL_CreateCompoundAddress( addressElements, dwNumAddElements,
                                    lpAddress, lpdwAddressSize, bAnsiInterface );
641 642 643
}


644

645 646 647 648 649 650 651 652 653 654 655 656 657
/********************************************************************
 *
 * Parses out chunks from the DirectPlay Address buffer by calling the
 * given callback function, with lpContext, for each of the chunks.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddress
( LPDIRECTPLAYLOBBYA iface,
  LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
  LPCVOID lpAddress,
  DWORD dwAddressSize,
  LPVOID lpContext )
{
658
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
659

660
  TRACE("(%p)->(%p,%p,0x%08x,%p)\n", This, lpEnumAddressCallback, lpAddress,
661
                                      dwAddressSize, lpContext );
662

663 664
  return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
}
665

666 667 668 669 670 671 672
static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddress
( LPDIRECTPLAYLOBBY iface,
  LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
  LPCVOID lpAddress,
  DWORD dwAddressSize,
  LPVOID lpContext )
{
673
  IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
674

675
  TRACE("(%p)->(%p,%p,0x%08x,%p)\n", This, lpEnumAddressCallback, lpAddress,
676 677 678 679 680
                                      dwAddressSize, lpContext );

  return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
}

681 682
HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
                         DWORD dwAddressSize, LPVOID lpContext )
683
{
684 685
  DWORD dwTotalSizeEnumerated = 0;

686
  /* FIXME: First chunk is always the total size chunk - Should we report it? */
687 688 689

  while ( dwTotalSizeEnumerated < dwAddressSize )
  {
690
    const DPADDRESS* lpElements = lpAddress;
691
    DWORD dwSizeThisEnumeration;
692 693

    /* Invoke the enum method. If false is returned, stop enumeration */
694 695
    if ( !lpEnumAddressCallback( &lpElements->guidDataType,
                                 lpElements->dwDataSize,
696
                                 (const BYTE *)lpElements + sizeof( DPADDRESS ),
697
                                 lpContext ) )
698 699 700 701 702
    {
      break;
    }

    dwSizeThisEnumeration  = sizeof( DPADDRESS ) + lpElements->dwDataSize;
Eric Pouech's avatar
Eric Pouech committed
703
    lpAddress = (const BYTE*) lpAddress + dwSizeThisEnumeration;
704 705 706 707
    dwTotalSizeEnumerated += dwSizeThisEnumeration;
  }

  return DP_OK;
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
}

/********************************************************************
 *
 * Enumerates all the address types that a given service provider needs to
 * build the DirectPlay Address.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddressTypes
( LPDIRECTPLAYLOBBYA iface,
  LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
  REFGUID guidSP,
  LPVOID lpContext,
  DWORD dwFlags )
{
723
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
724 725 726 727 728

  HKEY   hkResult;
  LPCSTR searchSubKey    = "SOFTWARE\\Microsoft\\DirectPlay\\Service Providers";
  DWORD  dwIndex, sizeOfSubKeyName=50;
  char   subKeyName[51];
729
  FILETIME filetime;
730

731
  TRACE(" (%p)->(%p,%p,%p,0x%08x)\n", This, lpEnumAddressTypeCallback, guidSP, lpContext, dwFlags );
732 733 734 735 736 737

  if( dwFlags != 0 )
  {
    return DPERR_INVALIDPARAMS;
  }

738
  if( !lpEnumAddressTypeCallback )
739 740 741 742 743 744 745 746 747 748 749
  {
     return DPERR_INVALIDPARAMS;
  }

  if( guidSP == NULL )
  {
    return DPERR_INVALIDOBJECT;
  }

    /* Need to loop over the service providers in the registry */
    if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
750
                         0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
751 752 753 754 755 756 757 758
    {
      /* Hmmm. Does this mean that there are no service providers? */
      ERR(": no service providers?\n");
      return DP_OK;
    }

    /* Traverse all the service providers we have available */
    for( dwIndex=0;
759 760 761
         RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
                        NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
         ++dwIndex, sizeOfSubKeyName=50 )
762 763 764 765 766 767 768
    {

      HKEY     hkServiceProvider, hkServiceProviderAt;
      GUID     serviceProviderGUID;
      DWORD    returnTypeGUID, sizeOfReturnBuffer = 50;
      char     atSubKey[51];
      char     returnBuffer[51];
769
      WCHAR    buff[51];
770
      DWORD    dwAtIndex;
771 772
      LPCSTR   atKey = "Address Types";
      LPCSTR   guidDataSubKey   = "Guid";
773
      FILETIME filetime;
774 775 776 777 778


      TRACE(" this time through: %s\n", subKeyName );

      /* Get a handle for this particular service provider */
779
      if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
780 781 782 783 784 785 786
                         &hkServiceProvider ) != ERROR_SUCCESS )
      {
         ERR(": what the heck is going on?\n" );
         continue;
      }

      if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
787
                            NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
788 789 790 791 792 793 794
                            &sizeOfReturnBuffer ) != ERROR_SUCCESS )
      {
        ERR(": missing GUID registry data members\n" );
        continue;
      }

      /* FIXME: Check return types to ensure we're interpreting data right */
795
      MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff)/sizeof(WCHAR) );
796
      CLSIDFromString( buff, &serviceProviderGUID );
797 798 799 800 801 802 803 804 805
      /* FIXME: Have I got a memory leak on the serviceProviderGUID? */

      /* Determine if this is the Service Provider that the user asked for */
      if( !IsEqualGUID( &serviceProviderGUID, guidSP ) )
      {
        continue;
      }

      /* Get a handle for this particular service provider */
806
      if( RegOpenKeyExA( hkServiceProvider, atKey, 0, KEY_READ,
807 808
                         &hkServiceProviderAt ) != ERROR_SUCCESS )
      {
809
        TRACE(": No Address Types registry data sub key/members\n" );
810 811 812 813 814
        break;
      }

      /* Traverse all the address type we have available */
      for( dwAtIndex=0;
815 816 817
           RegEnumKeyExA( hkServiceProviderAt, dwAtIndex, atSubKey, &sizeOfSubKeyName,
                          NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
           ++dwAtIndex, sizeOfSubKeyName=50 )
818 819 820 821
      {
        TRACE( "Found Address Type GUID %s\n", atSubKey );

        /* FIXME: Check return types to ensure we're interpreting data right */
822
        MultiByteToWideChar( CP_ACP, 0, atSubKey, -1, buff, sizeof(buff)/sizeof(WCHAR) );
823
        CLSIDFromString( buff, &serviceProviderGUID );
824
        /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
825

826 827 828 829 830 831 832 833 834 835 836
        /* The enumeration will return FALSE if we are not to continue */
        if( !lpEnumAddressTypeCallback( &serviceProviderGUID, lpContext, 0 ) )
        {
           WARN("lpEnumCallback returning FALSE\n" );
           break; /* FIXME: This most likely has to break from the procedure...*/
        }

      }

      /* We only enumerate address types for 1 GUID. We've found it, so quit looking */
      break;
837
    }
838 839

  return DP_OK;
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddressTypes
( LPDIRECTPLAYLOBBY iface,
  LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
  REFGUID guidSP,
  LPVOID lpContext,
  DWORD dwFlags )
{
  FIXME(":stub\n");
  return DPERR_OUTOFMEMORY;
}

/********************************************************************
 *
 * Enumerates what applications are registered with DirectPlay by
 * invoking the callback function with lpContext.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumLocalApplications
( LPDIRECTPLAYLOBBY iface,
  LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
  LPVOID lpContext,
  DWORD dwFlags )
{
865
  IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
866

867
  FIXME("(%p)->(%p,%p,0x%08x):stub\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
868 869 870 871 872 873 874 875 876 877

  return DPERR_OUTOFMEMORY;
}

static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumLocalApplications
( LPDIRECTPLAYLOBBYA iface,
  LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
  LPVOID lpContext,
  DWORD dwFlags )
{
878
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
879

880 881
  HKEY hkResult;
  LPCSTR searchSubKey    = "SOFTWARE\\Microsoft\\DirectPlay\\Applications";
882
  LPCSTR guidDataSubKey  = "Guid";
883 884
  DWORD dwIndex, sizeOfSubKeyName=50;
  char subKeyName[51];
885
  FILETIME filetime;
886

887
  TRACE("(%p)->(%p,%p,0x%08x)\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
888 889 890 891 892 893

  if( dwFlags != 0 )
  {
    return DPERR_INVALIDPARAMS;
  }

894
  if( !lpEnumLocalAppCallback )
895 896 897 898 899 900
  {
     return DPERR_INVALIDPARAMS;
  }

  /* Need to loop over the service providers in the registry */
  if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
901
                     0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
902 903 904 905 906 907 908 909
  {
    /* Hmmm. Does this mean that there are no service providers? */
    ERR(": no service providers?\n");
    return DP_OK;
  }

  /* Traverse all registered applications */
  for( dwIndex=0;
910 911
       RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
       ++dwIndex, sizeOfSubKeyName=50 )
912 913 914 915 916 917
  {

    HKEY       hkServiceProvider;
    GUID       serviceProviderGUID;
    DWORD      returnTypeGUID, sizeOfReturnBuffer = 50;
    char       returnBuffer[51];
918
    WCHAR      buff[51];
919 920 921 922 923
    DPLAPPINFO dplAppInfo;

    TRACE(" this time through: %s\n", subKeyName );

    /* Get a handle for this particular service provider */
924
    if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
925 926 927 928 929 930 931
                       &hkServiceProvider ) != ERROR_SUCCESS )
    {
       ERR(": what the heck is going on?\n" );
       continue;
    }

    if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
932
                          NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
933 934 935 936 937 938 939
                          &sizeOfReturnBuffer ) != ERROR_SUCCESS )
    {
      ERR(": missing GUID registry data members\n" );
      continue;
    }

    /* FIXME: Check return types to ensure we're interpreting data right */
940
    MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff)/sizeof(WCHAR) );
941
    CLSIDFromString( buff, &serviceProviderGUID );
942 943 944 945
    /* FIXME: Have I got a memory leak on the serviceProviderGUID? */

    dplAppInfo.dwSize               = sizeof( dplAppInfo );
    dplAppInfo.guidApplication      = serviceProviderGUID;
946
    dplAppInfo.u.lpszAppNameA = subKeyName;
947 948

    EnterCriticalSection( &This->unk->DPL_lock );
949

950 951 952 953 954 955 956 957 958 959 960 961
    memcpy( &This->dpl->hkCallbackKeyHack, &hkServiceProvider, sizeof( hkServiceProvider ) );

    if( !lpEnumLocalAppCallback( &dplAppInfo, lpContext, dwFlags ) )
    {
       LeaveCriticalSection( &This->unk->DPL_lock );
       break;
    }

    LeaveCriticalSection( &This->unk->DPL_lock );
  }

  return DP_OK;
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
}

/********************************************************************
 *
 * Retrieves the DPLCONNECTION structure that contains all the information
 * needed to start and connect an application. This was generated using
 * either the RunApplication or SetConnectionSettings methods.
 *
 * NOTES: If lpData is NULL then just return lpdwDataSize. This allows
 *        the data structure to be allocated by our caller which can then
 *        call this procedure/method again with a valid data pointer.
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_GetConnectionSettings
( LPDIRECTPLAYLOBBYA iface,
  DWORD dwAppID,
  LPVOID lpData,
  LPDWORD lpdwDataSize )
{
980
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
981
  HRESULT hr;
982

983
  TRACE("(%p)->(0x%08x,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
984

985
  EnterCriticalSection( &This->unk->DPL_lock );
986

987 988
  hr = DPLAYX_GetConnectionSettingsA( dwAppID,
                                      lpData,
989
                                      lpdwDataSize
990
                                    );
991

992
  LeaveCriticalSection( &This->unk->DPL_lock );
993

994
  return hr;
995 996 997 998 999 1000 1001 1002
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_GetConnectionSettings
( LPDIRECTPLAYLOBBY iface,
  DWORD dwAppID,
  LPVOID lpData,
  LPDWORD lpdwDataSize )
{
1003
  IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1004
  HRESULT hr;
1005

1006
  TRACE("(%p)->(0x%08x,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
1007

1008
  EnterCriticalSection( &This->unk->DPL_lock );
1009

1010 1011
  hr = DPLAYX_GetConnectionSettingsW( dwAppID,
                                      lpData,
1012
                                      lpdwDataSize
1013
                                    );
1014

1015 1016 1017
  LeaveCriticalSection( &This->unk->DPL_lock );

  return hr;
1018 1019 1020 1021
}

/********************************************************************
 *
1022
 * Retrieves the message sent between a lobby client and a DirectPlay
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
 * application. All messages are queued until received.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_ReceiveLobbyMessage
( LPDIRECTPLAYLOBBYA iface,
  DWORD dwFlags,
  DWORD dwAppID,
  LPDWORD lpdwMessageFlags,
  LPVOID lpData,
  LPDWORD lpdwDataSize )
{
1034
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
1035
  FIXME(":stub %p %08x %08x %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
         lpdwDataSize );
  return DPERR_OUTOFMEMORY;
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_ReceiveLobbyMessage
( LPDIRECTPLAYLOBBY iface,
  DWORD dwFlags,
  DWORD dwAppID,
  LPDWORD lpdwMessageFlags,
  LPVOID lpData,
  LPDWORD lpdwDataSize )
{
1048
  IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1049
  FIXME(":stub %p %08x %08x %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1050 1051 1052 1053
         lpdwDataSize );
  return DPERR_OUTOFMEMORY;
}

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
typedef struct tagRunApplicationEnumStruct
{
  IDirectPlayLobbyAImpl* This;

  GUID  appGUID;
  LPSTR lpszPath;
  LPSTR lpszFileName;
  LPSTR lpszCommandLine;
  LPSTR lpszCurrentDirectory;
} RunApplicationEnumStruct, *lpRunApplicationEnumStruct;

/* To be called by RunApplication to find how to invoke the function */
static BOOL CALLBACK RunApplicationA_EnumLocalApplications
( LPCDPLAPPINFO   lpAppInfo,
  LPVOID          lpContext,
  DWORD           dwFlags )
{
  lpRunApplicationEnumStruct lpData = (lpRunApplicationEnumStruct)lpContext;

  if( IsEqualGUID( &lpAppInfo->guidApplication, &lpData->appGUID ) )
  {
    char  returnBuffer[200];
    DWORD returnType, sizeOfReturnBuffer;
1077 1078 1079 1080
    LPCSTR clSubKey   = "CommandLine";
    LPCSTR cdSubKey   = "CurrentDirectory";
    LPCSTR fileSubKey = "File";
    LPCSTR pathSubKey = "Path";
1081

1082
    /* FIXME: Lazy man hack - dplay struct has the present reg key saved */
1083 1084

    sizeOfReturnBuffer = 200;
1085

1086 1087
    /* Get all the appropriate data from the registry */
    if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, clSubKey,
1088
                          NULL, &returnType, (LPBYTE)returnBuffer,
1089 1090 1091 1092 1093 1094
                          &sizeOfReturnBuffer ) != ERROR_SUCCESS )
    {
       ERR( ": missing CommandLine registry data member\n" );
    }
    else
    {
1095 1096
        if ((lpData->lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
            strcpy( lpData->lpszCommandLine, returnBuffer );
1097 1098 1099 1100 1101
    }

    sizeOfReturnBuffer = 200;

    if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, cdSubKey,
1102
                          NULL, &returnType, (LPBYTE)returnBuffer,
1103 1104 1105 1106 1107 1108
                          &sizeOfReturnBuffer ) != ERROR_SUCCESS )
    {
       ERR( ": missing CurrentDirectory registry data member\n" );
    }
    else
    {
1109 1110
        if ((lpData->lpszCurrentDirectory = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
            strcpy( lpData->lpszCurrentDirectory, returnBuffer );
1111 1112 1113 1114 1115
    }

    sizeOfReturnBuffer = 200;

    if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, fileSubKey,
1116
                          NULL, &returnType, (LPBYTE)returnBuffer,
1117 1118 1119 1120 1121 1122
                          &sizeOfReturnBuffer ) != ERROR_SUCCESS )
    {
       ERR( ": missing File registry data member\n" );
    }
    else
    {
1123 1124
        if ((lpData->lpszFileName = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
            strcpy( lpData->lpszFileName, returnBuffer );
1125 1126 1127 1128 1129
    }

    sizeOfReturnBuffer = 200;

    if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, pathSubKey,
1130
                          NULL, &returnType, (LPBYTE)returnBuffer,
1131 1132 1133 1134 1135 1136
                          &sizeOfReturnBuffer ) != ERROR_SUCCESS )
    {
       ERR( ": missing Path registry data member\n" );
    }
    else
    {
1137 1138
        if ((lpData->lpszPath = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
            strcpy( lpData->lpszPath, returnBuffer );
1139 1140 1141 1142 1143
    }

    return FALSE; /* No need to keep going as we found what we wanted */
  }

1144
  return TRUE; /* Keep enumerating, haven't found the application yet */
1145 1146
}

1147
static BOOL DPL_CreateAndSetLobbyHandles( DWORD dwDestProcessId, HANDLE hDestProcess,
1148
                                   LPHANDLE lphStart, LPHANDLE lphDeath,
1149 1150 1151
                                   LPHANDLE lphRead )
{
  /* These are the handles for the created process */
1152
  HANDLE hAppStart = 0, hAppDeath = 0, hAppRead  = 0;
1153 1154 1155 1156 1157 1158
  SECURITY_ATTRIBUTES s_attrib;

  s_attrib.nLength              = sizeof( s_attrib );
  s_attrib.lpSecurityDescriptor = NULL;
  s_attrib.bInheritHandle       = TRUE;

1159 1160 1161
  *lphStart = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
  *lphDeath = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
  *lphRead  = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
1162

1163 1164
  if( ( !DuplicateHandle( GetCurrentProcess(), *lphStart,
                          hDestProcess, &hAppStart,
1165
                          0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1166 1167
      ( !DuplicateHandle( GetCurrentProcess(), *lphDeath,
                          hDestProcess, &hAppDeath,
1168
                          0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1169 1170
      ( !DuplicateHandle( GetCurrentProcess(), *lphRead,
                          hDestProcess, &hAppRead,
1171 1172 1173
                          0, FALSE, DUPLICATE_SAME_ACCESS ) )
    )
  {
1174 1175 1176
    if (*lphStart) { CloseHandle(*lphStart); *lphStart = 0; }
    if (*lphDeath) { CloseHandle(*lphDeath); *lphDeath = 0; }
    if (*lphRead)  { CloseHandle(*lphRead);  *lphRead  = 0; }
1177 1178 1179 1180 1181
    /* FIXME: Handle leak... */
    ERR( "Unable to dup handles\n" );
    return FALSE;
  }

1182
  if( !DPLAYX_SetLobbyHandles( dwDestProcessId,
1183 1184
                               hAppStart, hAppDeath, hAppRead ) )
  {
1185
    /* FIXME: Handle leak... */
1186
    return FALSE;
1187 1188 1189 1190 1191 1192
  }

  return TRUE;
}


1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
/********************************************************************
 *
 * Starts an application and passes to it all the information to
 * connect to a session.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_RunApplication
( LPDIRECTPLAYLOBBYA iface,
  DWORD dwFlags,
  LPDWORD lpdwAppID,
  LPDPLCONNECTION lpConn,
  HANDLE hReceiveEvent )
{
1206
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
1207 1208 1209 1210 1211 1212
  HRESULT hr;
  RunApplicationEnumStruct enumData;
  char temp[200];
  STARTUPINFOA startupInfo;
  PROCESS_INFORMATION newProcessInfo;
  LPSTR appName;
1213
  DWORD dwSuspendCount;
1214
  HANDLE hStart, hDeath, hSettingRead;
1215

1216
  TRACE( "(%p)->(0x%08x,%p,%p,%p)\n",
1217
         This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1218 1219 1220 1221 1222 1223

  if( dwFlags != 0 )
  {
    return DPERR_INVALIDPARAMS;
  }

1224 1225 1226 1227 1228
  if( DPLAYX_AnyLobbiesWaitingForConnSettings() )
  {
    FIXME( "Waiting lobby not being handled correctly\n" );
  }

1229 1230 1231 1232 1233 1234
  EnterCriticalSection( &This->unk->DPL_lock );

  ZeroMemory( &enumData, sizeof( enumData ) );
  enumData.This    = This;
  enumData.appGUID = lpConn->lpSessionDesc->guidApplication;

1235
  /* Our callback function will fill up the enumData structure with all the information
1236 1237
     required to start a new process */
  IDirectPlayLobby_EnumLocalApplications( iface, RunApplicationA_EnumLocalApplications,
1238
                                          (&enumData), 0 );
1239 1240 1241 1242

  /* First the application name */
  strcpy( temp, enumData.lpszPath );
  strcat( temp, "\\" );
1243 1244
  strcat( temp, enumData.lpszFileName );
  HeapFree( GetProcessHeap(), 0, enumData.lpszPath );
1245
  HeapFree( GetProcessHeap(), 0, enumData.lpszFileName );
1246
  if ((appName = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 ))) strcpy( appName, temp );
1247 1248

  /* Now the command line */
1249
  strcat( temp, " " );
1250 1251
  strcat( temp, enumData.lpszCommandLine );
  HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1252 1253
  if ((enumData.lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 )))
      strcpy( enumData.lpszCommandLine, temp );
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273

  ZeroMemory( &startupInfo, sizeof( startupInfo ) );
  startupInfo.cb = sizeof( startupInfo );
  /* FIXME: Should any fields be filled in? */

  ZeroMemory( &newProcessInfo, sizeof( newProcessInfo ) );

  if( !CreateProcessA( appName,
                       enumData.lpszCommandLine,
                       NULL,
                       NULL,
                       FALSE,
                       CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE | CREATE_SUSPENDED, /* Creation Flags */
                       NULL,
                       enumData.lpszCurrentDirectory,
                       &startupInfo,
                       &newProcessInfo
                     )
    )
  {
1274
    ERR( "Failed to create process for app %s\n", appName );
1275 1276 1277 1278 1279

    HeapFree( GetProcessHeap(), 0, appName );
    HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
    HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );

1280
    LeaveCriticalSection( &This->unk->DPL_lock );
1281 1282
    return DPERR_CANTCREATEPROCESS;
  }
1283 1284 1285 1286 1287 1288

  HeapFree( GetProcessHeap(), 0, appName );
  HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
  HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );

  /* Reserve this global application id! */
1289
  if( !DPLAYX_CreateLobbyApplication( newProcessInfo.dwProcessId ) )
1290
  {
1291
    ERR( "Unable to create global application data for 0x%08x\n",
1292
           newProcessInfo.dwProcessId );
1293 1294 1295
  }

  hr = IDirectPlayLobby_SetConnectionSettings( iface, 0, newProcessInfo.dwProcessId, lpConn );
1296

1297 1298
  if( hr != DP_OK )
  {
1299
    ERR( "SetConnectionSettings failure %s\n", DPLAYX_HresultToString( hr ) );
1300
    LeaveCriticalSection( &This->unk->DPL_lock );
1301 1302 1303
    return hr;
  }

1304 1305 1306 1307
  /* Setup the handles for application notification */
  DPL_CreateAndSetLobbyHandles( newProcessInfo.dwProcessId,
                                newProcessInfo.hProcess,
                                &hStart, &hDeath, &hSettingRead );
1308

1309
  /* Setup the message thread ID */
1310
  This->dpl->dwMsgThread =
1311 1312 1313
    CreateLobbyMessageReceptionThread( hReceiveEvent, hStart, hDeath, hSettingRead );

  DPLAYX_SetLobbyMsgThreadId( newProcessInfo.dwProcessId, This->dpl->dwMsgThread );
1314 1315 1316

  LeaveCriticalSection( &This->unk->DPL_lock );

1317 1318 1319
  /* Everything seems to have been set correctly, update the dwAppID */
  *lpdwAppID = newProcessInfo.dwProcessId;

1320
  /* Unsuspend the process - should return the prev suspension count */
1321 1322
  if( ( dwSuspendCount = ResumeThread( newProcessInfo.hThread ) ) != 1 )
  {
1323
    ERR( "ResumeThread failed with 0x%08x\n", dwSuspendCount );
1324 1325
  }

1326
  return DP_OK;
1327 1328 1329 1330 1331 1332 1333 1334 1335
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_RunApplication
( LPDIRECTPLAYLOBBY iface,
  DWORD dwFlags,
  LPDWORD lpdwAppID,
  LPDPLCONNECTION lpConn,
  HANDLE hReceiveEvent )
{
1336
  IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1337
  FIXME( "(%p)->(0x%08x,%p,%p,%p):stub\n", This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
  return DPERR_OUTOFMEMORY;
}

/********************************************************************
 *
 * Sends a message between the application and the lobby client.
 * All messages are queued until received.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_SendLobbyMessage
( LPDIRECTPLAYLOBBYA iface,
  DWORD dwFlags,
  DWORD dwAppID,
  LPVOID lpData,
  DWORD dwDataSize )
{
  FIXME(":stub\n");
  return DPERR_OUTOFMEMORY;
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_SendLobbyMessage
( LPDIRECTPLAYLOBBY iface,
  DWORD dwFlags,
  DWORD dwAppID,
  LPVOID lpData,
  DWORD dwDataSize )
{
  FIXME(":stub\n");
  return DPERR_OUTOFMEMORY;
}

/********************************************************************
 *
 * Modifies the DPLCONNECTION structure to contain all information
 * needed to start and connect an application.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyWImpl_SetConnectionSettings
( LPDIRECTPLAYLOBBY iface,
  DWORD dwFlags,
  DWORD dwAppID,
  LPDPLCONNECTION lpConn )
{
1381
  IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1382
  HRESULT hr;
1383

1384
  TRACE("(%p)->(0x%08x,0x%08x,%p)\n", This, dwFlags, dwAppID, lpConn );
1385 1386 1387

  EnterCriticalSection( &This->unk->DPL_lock );

1388
  hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1389

Austin English's avatar
Austin English committed
1390
  /* FIXME: Don't think that this is supposed to fail, but the documentation
1391 1392 1393 1394 1395
            is somewhat sketchy. I'll try creating a lobby application
            for this... */
  if( hr == DPERR_NOTLOBBIED )
  {
    FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
1396 1397 1398 1399 1400
    if( dwAppID == 0 )
    {
       dwAppID = GetCurrentProcessId();
    }
    DPLAYX_CreateLobbyApplication( dwAppID );
1401 1402 1403
    hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
  }

1404 1405
  LeaveCriticalSection( &This->unk->DPL_lock );

1406
  return hr;
1407 1408 1409 1410 1411 1412 1413 1414
}

static HRESULT WINAPI IDirectPlayLobbyAImpl_SetConnectionSettings
( LPDIRECTPLAYLOBBYA iface,
  DWORD dwFlags,
  DWORD dwAppID,
  LPDPLCONNECTION lpConn )
{
1415
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
1416
  HRESULT hr;
1417

1418
  TRACE("(%p)->(0x%08x,0x%08x,%p)\n", This, dwFlags, dwAppID, lpConn );
1419 1420 1421

  EnterCriticalSection( &This->unk->DPL_lock );

1422
  hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1423

Austin English's avatar
Austin English committed
1424
  /* FIXME: Don't think that this is supposed to fail, but the documentation
1425 1426 1427 1428 1429 1430
            is somewhat sketchy. I'll try creating a lobby application
            for this... */
  if( hr == DPERR_NOTLOBBIED )
  {
    FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
    dwAppID = GetCurrentProcessId();
1431
    DPLAYX_CreateLobbyApplication( dwAppID );
1432 1433 1434
    hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
  }

1435 1436
  LeaveCriticalSection( &This->unk->DPL_lock );

1437
  return hr;
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465
}

/********************************************************************
 *
 * Registers an event that will be set when a lobby message is received.
 *
 */
static HRESULT WINAPI IDirectPlayLobbyAImpl_SetLobbyMessageEvent
( LPDIRECTPLAYLOBBYA iface,
  DWORD dwFlags,
  DWORD dwAppID,
  HANDLE hReceiveEvent )
{
  FIXME(":stub\n");
  return DPERR_OUTOFMEMORY;
}

static HRESULT WINAPI IDirectPlayLobbyWImpl_SetLobbyMessageEvent
( LPDIRECTPLAYLOBBY iface,
  DWORD dwFlags,
  DWORD dwAppID,
  HANDLE hReceiveEvent )
{
  FIXME(":stub\n");
  return DPERR_OUTOFMEMORY;
}


1466
/* DPL 2 methods */
1467 1468 1469 1470 1471 1472 1473
static HRESULT WINAPI IDirectPlayLobby2WImpl_CreateCompoundAddress
( LPDIRECTPLAYLOBBY2 iface,
  LPCDPCOMPOUNDADDRESSELEMENT lpElements,
  DWORD dwElementCount,
  LPVOID lpAddress,
  LPDWORD lpdwAddressSize )
{
1474
  return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, FALSE );
1475 1476 1477 1478 1479 1480 1481 1482 1483
}

static HRESULT WINAPI IDirectPlayLobby2AImpl_CreateCompoundAddress
( LPDIRECTPLAYLOBBY2A iface,
  LPCDPCOMPOUNDADDRESSELEMENT lpElements,
  DWORD dwElementCount,
  LPVOID lpAddress,
  LPDWORD lpdwAddressSize )
{
1484 1485 1486
  return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, TRUE );
}

1487
HRESULT DPL_CreateCompoundAddress
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
( LPCDPCOMPOUNDADDRESSELEMENT lpElements,
  DWORD dwElementCount,
  LPVOID lpAddress,
  LPDWORD lpdwAddressSize,
  BOOL bAnsiInterface )
{
  DWORD dwSizeRequired = 0;
  DWORD dwElements;
  LPCDPCOMPOUNDADDRESSELEMENT lpOrigElements = lpElements;

1498
  TRACE("(%p,0x%08x,%p,%p)\n", lpElements, dwElementCount, lpAddress, lpdwAddressSize );
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511

  /* Parameter check */
  if( ( lpElements == NULL ) ||
      ( dwElementCount == 0 )   /* FIXME: Not sure if this is a failure case */
    )
  {
    return DPERR_INVALIDPARAMS;
  }

  /* Add the total size chunk */
  dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DWORD );

  /* Calculate the size of the buffer required */
1512
  for ( dwElements = dwElementCount; dwElements > 0; --dwElements, ++lpElements )
1513 1514 1515 1516 1517
  {
    if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
         ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
       )
    {
1518
      dwSizeRequired += sizeof( DPADDRESS ) + sizeof( GUID );
1519 1520 1521 1522 1523 1524 1525
    }
    else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
              ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
              ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
            )
    {
      if( !bAnsiInterface )
1526
      {
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
        ERR( "Ansi GUIDs used for unicode interface\n" );
        return DPERR_INVALIDFLAGS;
      }

      dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize;
    }
    else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
              ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
              ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
            )
    {
      if( bAnsiInterface )
      {
        ERR( "Unicode GUIDs used for ansi interface\n" );
        return DPERR_INVALIDFLAGS;
      }

      FIXME( "Right size for unicode interface?\n" );
      dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize * sizeof( WCHAR );
    }
    else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
    {
      dwSizeRequired += sizeof( DPADDRESS ) + sizeof( WORD );
    }
    else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
    {
      FIXME( "Right size for unicode interface?\n" );
      dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DPCOMPORTADDRESS ); /* FIXME: Right size? */
    }
    else
    {
1558
      ERR( "Unknown GUID %s\n", debugstr_guid(&lpElements->guidDataType) );
1559
      return DPERR_INVALIDFLAGS;
1560 1561 1562 1563 1564
    }
  }

  /* The user wants to know how big a buffer to allocate for us */
  if( ( lpAddress == NULL ) ||
1565
      ( *lpdwAddressSize < dwSizeRequired )
1566 1567
    )
  {
1568
    *lpdwAddressSize = dwSizeRequired;
1569
    return DPERR_BUFFERTOOSMALL;
1570
  }
1571 1572 1573

  /* Add the total size chunk */
  {
1574
    LPDPADDRESS lpdpAddress = lpAddress;
1575

1576
    lpdpAddress->guidDataType = DPAID_TotalSize;
1577
    lpdpAddress->dwDataSize = sizeof( DWORD );
1578
    lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1579 1580

    *(LPDWORD)lpAddress = dwSizeRequired;
1581
    lpAddress = (char *) lpAddress + sizeof( DWORD );
1582 1583 1584
  }

  /* Calculate the size of the buffer required */
1585 1586 1587
  for( dwElements = dwElementCount, lpElements = lpOrigElements;
       dwElements > 0;
       --dwElements, ++lpElements )
1588 1589 1590 1591 1592
  {
    if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
         ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
       )
    {
1593
      LPDPADDRESS lpdpAddress = lpAddress;
1594

1595
      lpdpAddress->guidDataType = lpElements->guidDataType;
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 1605 1606
              ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
            )
    {
1607
      LPDPADDRESS lpdpAddress = lpAddress;
1608

1609
      lpdpAddress->guidDataType = lpElements->guidDataType;
1610
      lpdpAddress->dwDataSize = lpElements->dwDataSize;
1611
      lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1612

1613
      lstrcpynA( lpAddress, lpElements->lpData, lpElements->dwDataSize );
1614
      lpAddress = (char *) lpAddress + lpElements->dwDataSize;
1615 1616 1617 1618 1619 1620
    }
    else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
              ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
              ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
            )
    {
1621
      LPDPADDRESS lpdpAddress = lpAddress;
1622

1623
      lpdpAddress->guidDataType = lpElements->guidDataType;
1624
      lpdpAddress->dwDataSize = lpElements->dwDataSize;
1625
      lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1626

1627
      lstrcpynW( lpAddress, lpElements->lpData, lpElements->dwDataSize );
1628
      lpAddress = (char *) lpAddress + lpElements->dwDataSize * sizeof( WCHAR );
1629 1630 1631
    }
    else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
    {
1632
      LPDPADDRESS lpdpAddress = lpAddress;
1633

1634
      lpdpAddress->guidDataType = lpElements->guidDataType;
1635
      lpdpAddress->dwDataSize = lpElements->dwDataSize;
1636
      lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1637 1638

      *((LPWORD)lpAddress) = *((LPWORD)lpElements->lpData);
1639
      lpAddress = (char *) lpAddress + sizeof( WORD );
1640 1641 1642
    }
    else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
    {
1643
      LPDPADDRESS lpdpAddress = lpAddress;
1644

1645
      lpdpAddress->guidDataType = lpElements->guidDataType;
1646
      lpdpAddress->dwDataSize = lpElements->dwDataSize;
1647
      lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1648

1649
      CopyMemory( lpAddress, lpElements->lpData, sizeof( DPADDRESS ) );
1650
      lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1651 1652 1653 1654
    }
  }

  return DP_OK;
1655 1656 1657 1658 1659
}

/* DPL 3 methods */

static HRESULT WINAPI IDirectPlayLobby3WImpl_ConnectEx
1660
( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFIID riid,
1661
  LPVOID* lplpDP, IUnknown* pUnk )
1662
{
1663
  IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface ;
1664
  return DPL_ConnectEx( This, dwFlags, riid, lplpDP, pUnk );
1665 1666 1667
}

static HRESULT WINAPI IDirectPlayLobby3AImpl_ConnectEx
1668
( LPDIRECTPLAYLOBBY3A 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 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
}

static HRESULT WINAPI IDirectPlayLobby3WImpl_RegisterApplication
( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
{
  FIXME(":stub\n");
  return DP_OK;
}

static HRESULT WINAPI IDirectPlayLobby3AImpl_RegisterApplication
( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
{
  FIXME(":stub\n");
  return DP_OK;
}

static HRESULT WINAPI IDirectPlayLobby3WImpl_UnregisterApplication
( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFGUID lpAppDesc )
{
  FIXME(":stub\n");
  return DP_OK;
}

static HRESULT WINAPI IDirectPlayLobby3AImpl_UnregisterApplication
( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, REFGUID lpAppDesc )
{
  FIXME(":stub\n");
  return DP_OK;
}

static HRESULT WINAPI IDirectPlayLobby3WImpl_WaitForConnectionSettings
( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags )
{
1706 1707 1708
  HRESULT hr         = DP_OK;
  BOOL    bStartWait = (dwFlags & DPLWAIT_CANCEL) ? FALSE : TRUE;

1709
  TRACE( "(%p)->(0x%08x)\n", iface, dwFlags );
1710 1711 1712 1713

  if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
  {
    /* FIXME: What is the correct error return code? */
1714
    hr = DPERR_NOTLOBBIED;
1715 1716 1717
  }

  return hr;
1718 1719 1720 1721 1722
}

static HRESULT WINAPI IDirectPlayLobby3AImpl_WaitForConnectionSettings
( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags )
{
1723 1724 1725
  HRESULT hr         = DP_OK;
  BOOL    bStartWait = (dwFlags & DPLWAIT_CANCEL) ? FALSE : TRUE;

1726
  TRACE( "(%p)->(0x%08x)\n", iface, dwFlags );
1727 1728 1729 1730 1731 1732 1733 1734

  if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
  {
    /* FIXME: What is the correct error return code? */
    hr = DPERR_NOTLOBBIED;
  }

  return hr;
1735 1736 1737 1738 1739 1740 1741
}


/* Virtual Table definitions for DPL{1,2,3}{A,W} */

/* Note: Hack so we can reuse the old functions without compiler warnings */
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1742
# define XCAST(fun)     (typeof(directPlayLobbyAVT.fun))
1743 1744 1745 1746 1747 1748
#else
# define XCAST(fun)     (void*)
#endif

/* Direct Play Lobby 1 (ascii) Virtual Table for methods */
/* All lobby 1 methods are exactly the same except QueryInterface */
1749
static const IDirectPlayLobbyVtbl directPlayLobbyAVT =
1750 1751
{

1752 1753 1754
  XCAST(QueryInterface)DPL_QueryInterface,
  XCAST(AddRef)DPL_AddRef,
  XCAST(Release)DPL_Release,
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772

  IDirectPlayLobbyAImpl_Connect,
  IDirectPlayLobbyAImpl_CreateAddress,
  IDirectPlayLobbyAImpl_EnumAddress,
  IDirectPlayLobbyAImpl_EnumAddressTypes,
  IDirectPlayLobbyAImpl_EnumLocalApplications,
  IDirectPlayLobbyAImpl_GetConnectionSettings,
  IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
  IDirectPlayLobbyAImpl_RunApplication,
  IDirectPlayLobbyAImpl_SendLobbyMessage,
  IDirectPlayLobbyAImpl_SetConnectionSettings,
  IDirectPlayLobbyAImpl_SetLobbyMessageEvent
};
#undef XCAST


/* Note: Hack so we can reuse the old functions without compiler warnings */
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1773
# define XCAST(fun)     (typeof(directPlayLobbyWVT.fun))
1774 1775 1776 1777 1778
#else
# define XCAST(fun)     (void*)
#endif

/* Direct Play Lobby 1 (unicode) Virtual Table for methods */
1779
static const IDirectPlayLobbyVtbl directPlayLobbyWVT =
1780 1781
{

1782 1783 1784
  XCAST(QueryInterface)DPL_QueryInterface,
  XCAST(AddRef)DPL_AddRef,
  XCAST(Release)DPL_Release,
1785 1786

  IDirectPlayLobbyWImpl_Connect,
1787
  IDirectPlayLobbyWImpl_CreateAddress,
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
  IDirectPlayLobbyWImpl_EnumAddress,
  IDirectPlayLobbyWImpl_EnumAddressTypes,
  IDirectPlayLobbyWImpl_EnumLocalApplications,
  IDirectPlayLobbyWImpl_GetConnectionSettings,
  IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
  IDirectPlayLobbyWImpl_RunApplication,
  IDirectPlayLobbyWImpl_SendLobbyMessage,
  IDirectPlayLobbyWImpl_SetConnectionSettings,
  IDirectPlayLobbyWImpl_SetLobbyMessageEvent
};
#undef XCAST

/* Note: Hack so we can reuse the old functions without compiler warnings */
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1802
# define XCAST(fun)     (typeof(directPlayLobby2AVT.fun))
1803 1804 1805 1806 1807
#else
# define XCAST(fun)     (void*)
#endif

/* Direct Play Lobby 2 (ascii) Virtual Table for methods */
1808
static const IDirectPlayLobby2Vtbl directPlayLobby2AVT =
1809 1810
{

1811 1812 1813
  XCAST(QueryInterface)DPL_QueryInterface,
  XCAST(AddRef)DPL_AddRef,
  XCAST(Release)DPL_Release,
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826

  XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
  XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
  XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
  XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
  XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
  XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
  XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
  XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
  XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
  XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
  XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,

1827
  IDirectPlayLobby2AImpl_CreateCompoundAddress
1828 1829 1830 1831 1832
};
#undef XCAST

/* Note: Hack so we can reuse the old functions without compiler warnings */
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
Christian Costa's avatar
Christian Costa committed
1833
# define XCAST(fun)     (typeof(directPlayLobby2WVT.fun))
1834 1835 1836 1837 1838
#else
# define XCAST(fun)     (void*)
#endif

/* Direct Play Lobby 2 (unicode) Virtual Table for methods */
1839
static const IDirectPlayLobby2Vtbl directPlayLobby2WVT =
1840 1841
{

1842
  XCAST(QueryInterface)DPL_QueryInterface,
1843
  XCAST(AddRef)DPL_AddRef,
1844
  XCAST(Release)DPL_Release,
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865

  XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
  XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
  XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
  XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
  XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
  XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
  XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
  XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
  XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
  XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
  XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,

  IDirectPlayLobby2WImpl_CreateCompoundAddress
};
#undef XCAST

/* Direct Play Lobby 3 (ascii) Virtual Table for methods */

/* Note: Hack so we can reuse the old functions without compiler warnings */
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1866
# define XCAST(fun)     (typeof(directPlayLobby3AVT.fun))
1867 1868 1869 1870
#else
# define XCAST(fun)     (void*)
#endif

1871
static const IDirectPlayLobby3Vtbl directPlayLobby3AVT =
1872
{
1873 1874 1875
  XCAST(QueryInterface)DPL_QueryInterface,
  XCAST(AddRef)DPL_AddRef,
  XCAST(Release)DPL_Release,
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901

  XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
  XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
  XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
  XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
  XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
  XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
  XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
  XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
  XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
  XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
  XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,

  XCAST(CreateCompoundAddress)IDirectPlayLobby2AImpl_CreateCompoundAddress,

  IDirectPlayLobby3AImpl_ConnectEx,
  IDirectPlayLobby3AImpl_RegisterApplication,
  IDirectPlayLobby3AImpl_UnregisterApplication,
  IDirectPlayLobby3AImpl_WaitForConnectionSettings
};
#undef XCAST

/* Direct Play Lobby 3 (unicode) Virtual Table for methods */

/* Note: Hack so we can reuse the old functions without compiler warnings */
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1902
# define XCAST(fun)     (typeof(directPlayLobby3WVT.fun))
1903 1904 1905 1906
#else
# define XCAST(fun)     (void*)
#endif

1907
static const IDirectPlayLobby3Vtbl directPlayLobby3WVT =
1908
{
1909 1910 1911
  XCAST(QueryInterface)DPL_QueryInterface,
  XCAST(AddRef)DPL_AddRef,
  XCAST(Release)DPL_Release,
1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936

  XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
  XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
  XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
  XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
  XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
  XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
  XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
  XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
  XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
  XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
  XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,

  XCAST(CreateCompoundAddress)IDirectPlayLobby2WImpl_CreateCompoundAddress,

  IDirectPlayLobby3WImpl_ConnectEx,
  IDirectPlayLobby3WImpl_RegisterApplication,
  IDirectPlayLobby3WImpl_UnregisterApplication,
  IDirectPlayLobby3WImpl_WaitForConnectionSettings
};
#undef XCAST


/*********************************************************
 *
1937 1938 1939
 * Direct Play Lobby Interface Implementation
 *
 *********************************************************/
1940 1941 1942 1943 1944 1945 1946

/***************************************************************************
 *  DirectPlayLobbyCreateA   (DPLAYX.4)
 *
 */
HRESULT WINAPI DirectPlayLobbyCreateA( LPGUID lpGUIDDSP,
                                       LPDIRECTPLAYLOBBYA *lplpDPL,
1947
                                       IUnknown *lpUnk,
1948 1949 1950
                                       LPVOID lpData,
                                       DWORD dwDataSize )
{
1951
  TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08x\n",
1952 1953 1954 1955 1956
        lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);

  /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
   * equal 0. These fields are mostly for future expansion.
   */
1957
  if ( lpGUIDDSP || lpData || dwDataSize )
1958 1959 1960 1961 1962
  {
     *lplpDPL = NULL;
     return DPERR_INVALIDPARAMS;
  }

1963 1964 1965 1966 1967 1968 1969
  if( lpUnk )
  {
     *lplpDPL = NULL;
     ERR("Bad parameters!\n" );
     return CLASS_E_NOAGGREGATION;
  }

1970
  return DPL_CreateInterface( &IID_IDirectPlayLobbyA, (void**)lplpDPL );
1971 1972 1973 1974 1975 1976
}

/***************************************************************************
 *  DirectPlayLobbyCreateW   (DPLAYX.5)
 *
 */
1977
HRESULT WINAPI DirectPlayLobbyCreateW( LPGUID lpGUIDDSP,
1978 1979
                                       LPDIRECTPLAYLOBBY *lplpDPL,
                                       IUnknown *lpUnk,
1980
                                       LPVOID lpData,
1981 1982
                                       DWORD dwDataSize )
{
1983
  TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08x\n",
1984 1985
        lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);

1986
  /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
1987 1988
   * equal 0. These fields are mostly for future expansion.
   */
1989
  if ( lpGUIDDSP || lpData || dwDataSize )
1990 1991 1992 1993 1994 1995
  {
     *lplpDPL = NULL;
     ERR("Bad parameters!\n" );
     return DPERR_INVALIDPARAMS;
  }

1996 1997 1998 1999 2000 2001 2002
  if( lpUnk )
  {
     *lplpDPL = NULL;
     ERR("Bad parameters!\n" );
     return CLASS_E_NOAGGREGATION;
  }

2003
  return DPL_CreateInterface( &IID_IDirectPlayLobby, (void**)lplpDPL );
2004
}