source: trunk/src/DPlayX/dplobby.cpp@ 10367

Last change on this file since 10367 was 7940, checked in by sandervl, 24 years ago

compile fixes

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