configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / dplayx / dplobby.c
blobb3d3016944ad7345f540a29d551a9d0ae639217d
1 /* Direct Play Lobby 2 & 3 Implementation
3 * Copyright 1998,1999,2000 - Peter Hunnisett
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <string.h>
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "winreg.h"
28 #include "winnls.h"
29 #include "wine/debug.h"
31 #include "dplayx_global.h"
32 #include "dplayx_messages.h"
33 #include "dplayx_queue.h"
34 #include "dplobby.h"
35 #include "dpinit.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dplay);
39 /*****************************************************************************
40 * Predeclare the interface implementation structures
42 typedef struct IDirectPlayLobbyImpl IDirectPlayLobbyAImpl;
43 typedef struct IDirectPlayLobbyImpl IDirectPlayLobbyWImpl;
44 typedef struct IDirectPlayLobby2Impl IDirectPlayLobby2AImpl;
45 typedef struct IDirectPlayLobby2Impl IDirectPlayLobby2WImpl;
46 typedef struct IDirectPlayLobby3Impl IDirectPlayLobby3AImpl;
47 typedef struct IDirectPlayLobby3Impl IDirectPlayLobby3WImpl;
49 /* Forward declarations for this module helper methods */
50 HRESULT DPL_CreateCompoundAddress ( LPCDPCOMPOUNDADDRESSELEMENT lpElements, DWORD dwElementCount,
51 LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface );
53 static HRESULT DPL_CreateAddress( REFGUID guidSP, REFGUID guidDataType, LPCVOID lpData, DWORD dwDataSize,
54 LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface );
58 extern HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
59 DWORD dwAddressSize, LPVOID lpContext );
61 static HRESULT DPL_ConnectEx( IDirectPlayLobbyAImpl* This,
62 DWORD dwFlags, REFIID riid,
63 LPVOID* lplpDP, IUnknown* pUnk );
65 static BOOL DPL_CreateAndSetLobbyHandles( DWORD dwDestProcessId, HANDLE hDestProcess,
66 LPHANDLE lphStart, LPHANDLE lphDeath,
67 LPHANDLE lphRead );
70 /*****************************************************************************
71 * IDirectPlayLobby {1,2,3} implementation structure
73 * The philosophy behind this extra pointer dereference is that I wanted to
74 * have the same structure for all types of objects without having to do
75 * a lot of casting. I also only wanted to implement an interface in the
76 * object it was "released" with IUnknown interface being implemented in the 1 version.
77 * Of course, with these new interfaces comes the data required to keep the state required
78 * by these interfaces. So, basically, the pointers contain the data associated with
79 * a release. If you use the data associated with release 3 in a release 2 object, you'll
80 * get a run time trap, as that won't have any data.
83 struct DPLMSG
85 DPQ_ENTRY( DPLMSG ) msgs; /* Link to next queued message */
87 typedef struct DPLMSG* LPDPLMSG;
89 typedef struct tagDirectPlayLobbyIUnknownData
91 LONG ulObjRef;
92 CRITICAL_SECTION DPL_lock;
93 } DirectPlayLobbyIUnknownData;
95 typedef struct tagDirectPlayLobbyData
97 HKEY hkCallbackKeyHack;
98 DWORD dwMsgThread;
99 DPQ_HEAD( DPLMSG ) msgs; /* List of messages received */
100 } DirectPlayLobbyData;
102 typedef struct tagDirectPlayLobby2Data
104 BOOL dummy;
105 } DirectPlayLobby2Data;
107 typedef struct tagDirectPlayLobby3Data
109 BOOL dummy;
110 } DirectPlayLobby3Data;
112 #define DPL_IMPL_FIELDS \
113 LONG ulInterfaceRef; \
114 DirectPlayLobbyIUnknownData* unk; \
115 DirectPlayLobbyData* dpl; \
116 DirectPlayLobby2Data* dpl2; \
117 DirectPlayLobby3Data* dpl3;
119 struct IDirectPlayLobbyImpl
121 const IDirectPlayLobbyVtbl *lpVtbl;
122 DPL_IMPL_FIELDS
125 struct IDirectPlayLobby2Impl
127 const IDirectPlayLobby2Vtbl *lpVtbl;
128 DPL_IMPL_FIELDS
131 struct IDirectPlayLobby3Impl
133 const IDirectPlayLobby3Vtbl *lpVtbl;
134 DPL_IMPL_FIELDS
137 /* Forward declarations of virtual tables */
138 static const IDirectPlayLobbyVtbl directPlayLobbyWVT;
139 static const IDirectPlayLobby2Vtbl directPlayLobby2WVT;
140 static const IDirectPlayLobby3Vtbl directPlayLobby3WVT;
142 static const IDirectPlayLobbyVtbl directPlayLobbyAVT;
143 static const IDirectPlayLobby2Vtbl directPlayLobby2AVT;
144 static const IDirectPlayLobby3Vtbl directPlayLobby3AVT;
146 static BOOL DPL_CreateIUnknown( LPVOID lpDPL )
148 IDirectPlayLobbyAImpl *This = lpDPL;
150 This->unk = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->unk) ) );
151 if ( This->unk == NULL )
153 return FALSE;
156 InitializeCriticalSection( &This->unk->DPL_lock );
157 This->unk->DPL_lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectPlayLobbyAImpl*->DirectPlayLobbyIUnknownData*->DPL_lock");
159 return TRUE;
162 static BOOL DPL_DestroyIUnknown( LPVOID lpDPL )
164 IDirectPlayLobbyAImpl *This = lpDPL;
166 This->unk->DPL_lock.DebugInfo->Spare[0] = 0;
167 DeleteCriticalSection( &This->unk->DPL_lock );
168 HeapFree( GetProcessHeap(), 0, This->unk );
170 return TRUE;
173 static BOOL DPL_CreateLobby1( LPVOID lpDPL )
175 IDirectPlayLobbyAImpl *This = lpDPL;
177 This->dpl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->dpl) ) );
178 if ( This->dpl == NULL )
180 return FALSE;
183 DPQ_INIT( This->dpl->msgs );
185 return TRUE;
188 static BOOL DPL_DestroyLobby1( LPVOID lpDPL )
190 IDirectPlayLobbyAImpl *This = lpDPL;
192 if( This->dpl->dwMsgThread )
194 FIXME( "Should kill the msg thread\n" );
197 DPQ_DELETEQ( This->dpl->msgs, msgs, LPDPLMSG, cbDeleteElemFromHeap );
199 /* Delete the contents */
200 HeapFree( GetProcessHeap(), 0, This->dpl );
202 return TRUE;
205 static BOOL DPL_CreateLobby2( LPVOID lpDPL )
207 IDirectPlayLobby2AImpl *This = lpDPL;
209 This->dpl2 = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->dpl2) ) );
210 if ( This->dpl2 == NULL )
212 return FALSE;
215 return TRUE;
218 static BOOL DPL_DestroyLobby2( LPVOID lpDPL )
220 IDirectPlayLobby2AImpl *This = lpDPL;
222 HeapFree( GetProcessHeap(), 0, This->dpl2 );
224 return TRUE;
227 static BOOL DPL_CreateLobby3( LPVOID lpDPL )
229 IDirectPlayLobby3AImpl *This = lpDPL;
231 This->dpl3 = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->dpl3) ) );
232 if ( This->dpl3 == NULL )
234 return FALSE;
237 return TRUE;
240 static BOOL DPL_DestroyLobby3( LPVOID lpDPL )
242 IDirectPlayLobby3AImpl *This = lpDPL;
244 HeapFree( GetProcessHeap(), 0, This->dpl3 );
246 return TRUE;
250 /* The COM interface for upversioning an interface
251 * We've been given a GUID (riid) and we need to replace the present
252 * interface with that of the requested interface.
254 * Snip from some Microsoft document:
255 * There are four requirements for implementations of QueryInterface (In these
256 * cases, "must succeed" means "must succeed barring catastrophic failure."):
258 * * The set of interfaces accessible on an object through
259 * IUnknown::QueryInterface must be static, not dynamic. This means that
260 * if a call to QueryInterface for a pointer to a specified interface
261 * succeeds the first time, it must succeed again, and if it fails the
262 * first time, it must fail on all subsequent queries.
263 * * It must be symmetric ~W if a client holds a pointer to an interface on
264 * an object, and queries for that interface, the call must succeed.
265 * * It must be reflexive ~W if a client holding a pointer to one interface
266 * queries successfully for another, a query through the obtained pointer
267 * for the first interface must succeed.
268 * * It must be transitive ~W if a client holding a pointer to one interface
269 * queries successfully for a second, and through that pointer queries
270 * successfully for a third interface, a query for the first interface
271 * through the pointer for the third interface must succeed.
273 HRESULT DPL_CreateInterface
274 ( REFIID riid, LPVOID* ppvObj )
276 TRACE( " for %s\n", debugstr_guid( riid ) );
278 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
279 sizeof( IDirectPlayLobbyWImpl ) );
281 if( *ppvObj == NULL )
283 return DPERR_OUTOFMEMORY;
286 if( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
288 IDirectPlayLobbyWImpl *This = *ppvObj;
289 This->lpVtbl = &directPlayLobbyWVT;
291 else if( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
293 IDirectPlayLobbyAImpl *This = *ppvObj;
294 This->lpVtbl = &directPlayLobbyAVT;
296 else if( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
298 IDirectPlayLobby2WImpl *This = *ppvObj;
299 This->lpVtbl = &directPlayLobby2WVT;
301 else if( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
303 IDirectPlayLobby2AImpl *This = *ppvObj;
304 This->lpVtbl = &directPlayLobby2AVT;
306 else if( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
308 IDirectPlayLobby3WImpl *This = *ppvObj;
309 This->lpVtbl = &directPlayLobby3WVT;
311 else if( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
313 IDirectPlayLobby3AImpl *This = *ppvObj;
314 This->lpVtbl = &directPlayLobby3AVT;
316 else
318 /* Unsupported interface */
319 HeapFree( GetProcessHeap(), 0, *ppvObj );
320 *ppvObj = NULL;
322 return E_NOINTERFACE;
325 /* Initialize it */
326 if ( DPL_CreateIUnknown( *ppvObj ) &&
327 DPL_CreateLobby1( *ppvObj ) &&
328 DPL_CreateLobby2( *ppvObj ) &&
329 DPL_CreateLobby3( *ppvObj )
332 IDirectPlayLobby_AddRef( (LPDIRECTPLAYLOBBY)*ppvObj );
333 return S_OK;
336 /* Initialize failed, destroy it */
337 DPL_DestroyLobby3( *ppvObj );
338 DPL_DestroyLobby2( *ppvObj );
339 DPL_DestroyLobby1( *ppvObj );
340 DPL_DestroyIUnknown( *ppvObj );
341 HeapFree( GetProcessHeap(), 0, *ppvObj );
343 *ppvObj = NULL;
344 return DPERR_NOMEMORY;
347 static HRESULT WINAPI DPL_QueryInterface
348 ( LPDIRECTPLAYLOBBYA iface,
349 REFIID riid,
350 LPVOID* ppvObj )
352 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
353 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
355 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
356 sizeof( *This ) );
358 if( *ppvObj == NULL )
360 return DPERR_OUTOFMEMORY;
363 CopyMemory( *ppvObj, This, sizeof( *This ) );
364 (*(IDirectPlayLobbyAImpl**)ppvObj)->ulInterfaceRef = 0;
366 if( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
368 IDirectPlayLobbyWImpl *This = *ppvObj;
369 This->lpVtbl = &directPlayLobbyWVT;
371 else if( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
373 IDirectPlayLobbyAImpl *This = *ppvObj;
374 This->lpVtbl = &directPlayLobbyAVT;
376 else if( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
378 IDirectPlayLobby2WImpl *This = *ppvObj;
379 This->lpVtbl = &directPlayLobby2WVT;
381 else if( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
383 IDirectPlayLobby2AImpl *This = *ppvObj;
384 This->lpVtbl = &directPlayLobby2AVT;
386 else if( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
388 IDirectPlayLobby3WImpl *This = *ppvObj;
389 This->lpVtbl = &directPlayLobby3WVT;
391 else if( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
393 IDirectPlayLobby3AImpl *This = *ppvObj;
394 This->lpVtbl = &directPlayLobby3AVT;
396 else
398 /* Unsupported interface */
399 HeapFree( GetProcessHeap(), 0, *ppvObj );
400 *ppvObj = NULL;
402 return E_NOINTERFACE;
405 IDirectPlayLobby_AddRef( (LPDIRECTPLAYLOBBY)*ppvObj );
407 return S_OK;
411 * Simple procedure. Just increment the reference count to this
412 * structure and return the new reference count.
414 static ULONG WINAPI DPL_AddRef
415 ( LPDIRECTPLAYLOBBY iface )
417 ULONG ulInterfaceRefCount, ulObjRefCount;
418 IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
420 ulObjRefCount = InterlockedIncrement( &This->unk->ulObjRef );
421 ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );
423 TRACE( "ref count incremented to %u:%u for %p\n",
424 ulInterfaceRefCount, ulObjRefCount, This );
426 return ulObjRefCount;
430 * Simple COM procedure. Decrease the reference count to this object.
431 * If the object no longer has any reference counts, free up the associated
432 * memory.
434 static ULONG WINAPI DPL_Release
435 ( LPDIRECTPLAYLOBBYA iface )
437 ULONG ulInterfaceRefCount, ulObjRefCount;
438 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
440 ulObjRefCount = InterlockedDecrement( &This->unk->ulObjRef );
441 ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );
443 TRACE( "ref count decremented to %u:%u for %p\n",
444 ulInterfaceRefCount, ulObjRefCount, This );
446 /* Deallocate if this is the last reference to the object */
447 if( ulObjRefCount == 0 )
449 DPL_DestroyLobby3( This );
450 DPL_DestroyLobby2( This );
451 DPL_DestroyLobby1( This );
452 DPL_DestroyIUnknown( This );
455 if( ulInterfaceRefCount == 0 )
457 HeapFree( GetProcessHeap(), 0, This );
460 return ulInterfaceRefCount;
464 /********************************************************************
466 * Connects an application to the session specified by the DPLCONNECTION
467 * structure currently stored with the DirectPlayLobby object.
469 * Returns an IDirectPlay interface.
472 static HRESULT DPL_ConnectEx
473 ( IDirectPlayLobbyAImpl* This,
474 DWORD dwFlags,
475 REFIID riid,
476 LPVOID* lplpDP,
477 IUnknown* pUnk)
479 HRESULT hr;
480 DWORD dwOpenFlags = 0;
481 DWORD dwConnSize = 0;
482 LPDPLCONNECTION lpConn;
484 FIXME("(%p)->(0x%08x,%p,%p): semi stub\n", This, dwFlags, lplpDP, pUnk );
486 if( pUnk )
488 return DPERR_INVALIDPARAMS;
491 /* Backwards compatibility */
492 if( dwFlags == 0 )
494 dwFlags = DPCONNECT_RETURNSTATUS;
497 /* Create the DirectPlay interface */
498 if( ( hr = DP_CreateInterface( riid, lplpDP ) ) != DP_OK )
500 ERR( "error creating interface for %s:%s.\n",
501 debugstr_guid( riid ), DPLAYX_HresultToString( hr ) );
502 return hr;
505 /* FIXME: Is it safe/correct to use appID of 0? */
506 hr = IDirectPlayLobby_GetConnectionSettings( (LPDIRECTPLAYLOBBY)This,
507 0, NULL, &dwConnSize );
508 if( hr != DPERR_BUFFERTOOSMALL )
510 return hr;
513 lpConn = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwConnSize );
515 if( lpConn == NULL )
517 return DPERR_NOMEMORY;
520 /* FIXME: Is it safe/correct to use appID of 0? */
521 hr = IDirectPlayLobby_GetConnectionSettings( (LPDIRECTPLAYLOBBY)This,
522 0, lpConn, &dwConnSize );
523 if( FAILED( hr ) )
525 HeapFree( GetProcessHeap(), 0, lpConn );
526 return hr;
529 #if 0
530 /* - Need to call IDirectPlay::EnumConnections with the service provider to get that good information
531 * - Need to call CreateAddress to create the lpConnection param for IDirectPlay::InitializeConnection
532 * - Call IDirectPlay::InitializeConnection
535 /* Now initialize the Service Provider */
536 hr = IDirectPlayX_InitializeConnection( (*(LPDIRECTPLAY2*)lplpDP),
537 #endif
540 /* Setup flags to pass into DirectPlay::Open */
541 if( dwFlags & DPCONNECT_RETURNSTATUS )
543 dwOpenFlags |= DPOPEN_RETURNSTATUS;
545 dwOpenFlags |= lpConn->dwFlags;
547 hr = IDirectPlayX_Open( (*(LPDIRECTPLAY2*)lplpDP), lpConn->lpSessionDesc,
548 dwOpenFlags );
550 HeapFree( GetProcessHeap(), 0, lpConn );
552 return hr;
555 static HRESULT WINAPI IDirectPlayLobbyAImpl_Connect
556 ( LPDIRECTPLAYLOBBYA iface,
557 DWORD dwFlags,
558 LPDIRECTPLAY2A* lplpDP,
559 IUnknown* pUnk)
561 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
562 return DPL_ConnectEx( This, dwFlags, &IID_IDirectPlay2A,
563 (LPVOID)lplpDP, pUnk );
566 static HRESULT WINAPI IDirectPlayLobbyWImpl_Connect
567 ( LPDIRECTPLAYLOBBY iface,
568 DWORD dwFlags,
569 LPDIRECTPLAY2* lplpDP,
570 IUnknown* pUnk)
572 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface; /* Yes cast to A */
573 return DPL_ConnectEx( This, dwFlags, &IID_IDirectPlay2,
574 (LPVOID)lplpDP, pUnk );
577 /********************************************************************
579 * Creates a DirectPlay Address, given a service provider-specific network
580 * address.
581 * Returns an address contains the globally unique identifier
582 * (GUID) of the service provider and data that the service provider can
583 * interpret as a network address.
585 * NOTE: It appears that this method is supposed to be really really stupid
586 * with no error checking on the contents.
588 static HRESULT WINAPI IDirectPlayLobbyAImpl_CreateAddress
589 ( LPDIRECTPLAYLOBBYA iface,
590 REFGUID guidSP,
591 REFGUID guidDataType,
592 LPCVOID lpData,
593 DWORD dwDataSize,
594 LPVOID lpAddress,
595 LPDWORD lpdwAddressSize )
597 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
598 lpAddress, lpdwAddressSize, TRUE );
601 static HRESULT WINAPI IDirectPlayLobbyWImpl_CreateAddress
602 ( LPDIRECTPLAYLOBBY iface,
603 REFGUID guidSP,
604 REFGUID guidDataType,
605 LPCVOID lpData,
606 DWORD dwDataSize,
607 LPVOID lpAddress,
608 LPDWORD lpdwAddressSize )
610 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
611 lpAddress, lpdwAddressSize, FALSE );
614 static HRESULT DPL_CreateAddress(
615 REFGUID guidSP,
616 REFGUID guidDataType,
617 LPCVOID lpData,
618 DWORD dwDataSize,
619 LPVOID lpAddress,
620 LPDWORD lpdwAddressSize,
621 BOOL bAnsiInterface )
623 const DWORD dwNumAddElements = 2; /* Service Provide & address data type */
624 DPCOMPOUNDADDRESSELEMENT addressElements[ 2 /* dwNumAddElements */ ];
626 TRACE( "(%p)->(%p,%p,0x%08x,%p,%p,%d)\n", guidSP, guidDataType, lpData, dwDataSize,
627 lpAddress, lpdwAddressSize, bAnsiInterface );
629 addressElements[ 0 ].guidDataType = DPAID_ServiceProvider;
630 addressElements[ 0 ].dwDataSize = sizeof( GUID );
631 addressElements[ 0 ].lpData = (LPVOID)guidSP;
633 addressElements[ 1 ].guidDataType = *guidDataType;
634 addressElements[ 1 ].dwDataSize = dwDataSize;
635 addressElements[ 1 ].lpData = (LPVOID)lpData;
637 /* Call CreateCompoundAddress to cut down on code.
638 NOTE: We can do this because we don't support DPL 1 interfaces! */
639 return DPL_CreateCompoundAddress( addressElements, dwNumAddElements,
640 lpAddress, lpdwAddressSize, bAnsiInterface );
645 /********************************************************************
647 * Parses out chunks from the DirectPlay Address buffer by calling the
648 * given callback function, with lpContext, for each of the chunks.
651 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddress
652 ( LPDIRECTPLAYLOBBYA iface,
653 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
654 LPCVOID lpAddress,
655 DWORD dwAddressSize,
656 LPVOID lpContext )
658 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
660 TRACE("(%p)->(%p,%p,0x%08x,%p)\n", This, lpEnumAddressCallback, lpAddress,
661 dwAddressSize, lpContext );
663 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
666 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddress
667 ( LPDIRECTPLAYLOBBY iface,
668 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
669 LPCVOID lpAddress,
670 DWORD dwAddressSize,
671 LPVOID lpContext )
673 IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
675 TRACE("(%p)->(%p,%p,0x%08x,%p)\n", This, lpEnumAddressCallback, lpAddress,
676 dwAddressSize, lpContext );
678 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
681 HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
682 DWORD dwAddressSize, LPVOID lpContext )
684 DWORD dwTotalSizeEnumerated = 0;
686 /* FIXME: First chunk is always the total size chunk - Should we report it? */
688 while ( dwTotalSizeEnumerated < dwAddressSize )
690 const DPADDRESS* lpElements = lpAddress;
691 DWORD dwSizeThisEnumeration;
693 /* Invoke the enum method. If false is returned, stop enumeration */
694 if ( !lpEnumAddressCallback( &lpElements->guidDataType,
695 lpElements->dwDataSize,
696 (const BYTE *)lpElements + sizeof( DPADDRESS ),
697 lpContext ) )
699 break;
702 dwSizeThisEnumeration = sizeof( DPADDRESS ) + lpElements->dwDataSize;
703 lpAddress = (const BYTE*) lpAddress + dwSizeThisEnumeration;
704 dwTotalSizeEnumerated += dwSizeThisEnumeration;
707 return DP_OK;
710 /********************************************************************
712 * Enumerates all the address types that a given service provider needs to
713 * build the DirectPlay Address.
716 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddressTypes
717 ( LPDIRECTPLAYLOBBYA iface,
718 LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
719 REFGUID guidSP,
720 LPVOID lpContext,
721 DWORD dwFlags )
723 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
725 HKEY hkResult;
726 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Service Providers";
727 DWORD dwIndex, sizeOfSubKeyName=50;
728 char subKeyName[51];
729 FILETIME filetime;
731 TRACE(" (%p)->(%p,%p,%p,0x%08x)\n", This, lpEnumAddressTypeCallback, guidSP, lpContext, dwFlags );
733 if( dwFlags != 0 )
735 return DPERR_INVALIDPARAMS;
738 if( !lpEnumAddressTypeCallback )
740 return DPERR_INVALIDPARAMS;
743 if( guidSP == NULL )
745 return DPERR_INVALIDOBJECT;
748 /* Need to loop over the service providers in the registry */
749 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
750 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
752 /* Hmmm. Does this mean that there are no service providers? */
753 ERR(": no service providers?\n");
754 return DP_OK;
757 /* Traverse all the service providers we have available */
758 for( dwIndex=0;
759 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
760 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
761 ++dwIndex, sizeOfSubKeyName=50 )
764 HKEY hkServiceProvider, hkServiceProviderAt;
765 GUID serviceProviderGUID;
766 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
767 char atSubKey[51];
768 char returnBuffer[51];
769 WCHAR buff[51];
770 DWORD dwAtIndex;
771 LPCSTR atKey = "Address Types";
772 LPCSTR guidDataSubKey = "Guid";
773 FILETIME filetime;
776 TRACE(" this time through: %s\n", subKeyName );
778 /* Get a handle for this particular service provider */
779 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
780 &hkServiceProvider ) != ERROR_SUCCESS )
782 ERR(": what the heck is going on?\n" );
783 continue;
786 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
787 NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
788 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
790 ERR(": missing GUID registry data members\n" );
791 continue;
794 /* 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 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
799 /* Determine if this is the Service Provider that the user asked for */
800 if( !IsEqualGUID( &serviceProviderGUID, guidSP ) )
802 continue;
805 /* Get a handle for this particular service provider */
806 if( RegOpenKeyExA( hkServiceProvider, atKey, 0, KEY_READ,
807 &hkServiceProviderAt ) != ERROR_SUCCESS )
809 TRACE(": No Address Types registry data sub key/members\n" );
810 break;
813 /* Traverse all the address type we have available */
814 for( dwAtIndex=0;
815 RegEnumKeyExA( hkServiceProviderAt, dwAtIndex, atSubKey, &sizeOfSubKeyName,
816 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
817 ++dwAtIndex, sizeOfSubKeyName=50 )
819 TRACE( "Found Address Type GUID %s\n", atSubKey );
821 /* 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? */
826 /* The enumeration will return FALSE if we are not to continue */
827 if( !lpEnumAddressTypeCallback( &serviceProviderGUID, lpContext, 0 ) )
829 WARN("lpEnumCallback returning FALSE\n" );
830 break; /* FIXME: This most likely has to break from the procedure...*/
835 /* We only enumerate address types for 1 GUID. We've found it, so quit looking */
836 break;
839 return DP_OK;
842 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddressTypes
843 ( LPDIRECTPLAYLOBBY iface,
844 LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
845 REFGUID guidSP,
846 LPVOID lpContext,
847 DWORD dwFlags )
849 FIXME(":stub\n");
850 return DPERR_OUTOFMEMORY;
853 /********************************************************************
855 * Enumerates what applications are registered with DirectPlay by
856 * invoking the callback function with lpContext.
859 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumLocalApplications
860 ( LPDIRECTPLAYLOBBY iface,
861 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
862 LPVOID lpContext,
863 DWORD dwFlags )
865 IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
867 FIXME("(%p)->(%p,%p,0x%08x):stub\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
869 return DPERR_OUTOFMEMORY;
872 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumLocalApplications
873 ( LPDIRECTPLAYLOBBYA iface,
874 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
875 LPVOID lpContext,
876 DWORD dwFlags )
878 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
880 HKEY hkResult;
881 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Applications";
882 LPCSTR guidDataSubKey = "Guid";
883 DWORD dwIndex, sizeOfSubKeyName=50;
884 char subKeyName[51];
885 FILETIME filetime;
887 TRACE("(%p)->(%p,%p,0x%08x)\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
889 if( dwFlags != 0 )
891 return DPERR_INVALIDPARAMS;
894 if( !lpEnumLocalAppCallback )
896 return DPERR_INVALIDPARAMS;
899 /* Need to loop over the service providers in the registry */
900 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
901 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
903 /* Hmmm. Does this mean that there are no service providers? */
904 ERR(": no service providers?\n");
905 return DP_OK;
908 /* Traverse all registered applications */
909 for( dwIndex=0;
910 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
911 ++dwIndex, sizeOfSubKeyName=50 )
914 HKEY hkServiceProvider;
915 GUID serviceProviderGUID;
916 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
917 char returnBuffer[51];
918 WCHAR buff[51];
919 DPLAPPINFO dplAppInfo;
921 TRACE(" this time through: %s\n", subKeyName );
923 /* Get a handle for this particular service provider */
924 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
925 &hkServiceProvider ) != ERROR_SUCCESS )
927 ERR(": what the heck is going on?\n" );
928 continue;
931 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
932 NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
933 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
935 ERR(": missing GUID registry data members\n" );
936 continue;
939 /* 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 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
944 dplAppInfo.dwSize = sizeof( dplAppInfo );
945 dplAppInfo.guidApplication = serviceProviderGUID;
946 dplAppInfo.u.lpszAppNameA = subKeyName;
948 EnterCriticalSection( &This->unk->DPL_lock );
950 memcpy( &This->dpl->hkCallbackKeyHack, &hkServiceProvider, sizeof( hkServiceProvider ) );
952 if( !lpEnumLocalAppCallback( &dplAppInfo, lpContext, dwFlags ) )
954 LeaveCriticalSection( &This->unk->DPL_lock );
955 break;
958 LeaveCriticalSection( &This->unk->DPL_lock );
961 return DP_OK;
964 /********************************************************************
966 * Retrieves the DPLCONNECTION structure that contains all the information
967 * needed to start and connect an application. This was generated using
968 * either the RunApplication or SetConnectionSettings methods.
970 * NOTES: If lpData is NULL then just return lpdwDataSize. This allows
971 * the data structure to be allocated by our caller which can then
972 * call this procedure/method again with a valid data pointer.
974 static HRESULT WINAPI IDirectPlayLobbyAImpl_GetConnectionSettings
975 ( LPDIRECTPLAYLOBBYA iface,
976 DWORD dwAppID,
977 LPVOID lpData,
978 LPDWORD lpdwDataSize )
980 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
981 HRESULT hr;
983 TRACE("(%p)->(0x%08x,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
985 EnterCriticalSection( &This->unk->DPL_lock );
987 hr = DPLAYX_GetConnectionSettingsA( dwAppID,
988 lpData,
989 lpdwDataSize
992 LeaveCriticalSection( &This->unk->DPL_lock );
994 return hr;
997 static HRESULT WINAPI IDirectPlayLobbyWImpl_GetConnectionSettings
998 ( LPDIRECTPLAYLOBBY iface,
999 DWORD dwAppID,
1000 LPVOID lpData,
1001 LPDWORD lpdwDataSize )
1003 IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1004 HRESULT hr;
1006 TRACE("(%p)->(0x%08x,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
1008 EnterCriticalSection( &This->unk->DPL_lock );
1010 hr = DPLAYX_GetConnectionSettingsW( dwAppID,
1011 lpData,
1012 lpdwDataSize
1015 LeaveCriticalSection( &This->unk->DPL_lock );
1017 return hr;
1020 /********************************************************************
1022 * Retrieves the message sent between a lobby client and a DirectPlay
1023 * application. All messages are queued until received.
1026 static HRESULT WINAPI IDirectPlayLobbyAImpl_ReceiveLobbyMessage
1027 ( LPDIRECTPLAYLOBBYA iface,
1028 DWORD dwFlags,
1029 DWORD dwAppID,
1030 LPDWORD lpdwMessageFlags,
1031 LPVOID lpData,
1032 LPDWORD lpdwDataSize )
1034 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
1035 FIXME(":stub %p %08x %08x %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1036 lpdwDataSize );
1037 return DPERR_OUTOFMEMORY;
1040 static HRESULT WINAPI IDirectPlayLobbyWImpl_ReceiveLobbyMessage
1041 ( LPDIRECTPLAYLOBBY iface,
1042 DWORD dwFlags,
1043 DWORD dwAppID,
1044 LPDWORD lpdwMessageFlags,
1045 LPVOID lpData,
1046 LPDWORD lpdwDataSize )
1048 IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1049 FIXME(":stub %p %08x %08x %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1050 lpdwDataSize );
1051 return DPERR_OUTOFMEMORY;
1054 typedef struct tagRunApplicationEnumStruct
1056 IDirectPlayLobbyAImpl* This;
1058 GUID appGUID;
1059 LPSTR lpszPath;
1060 LPSTR lpszFileName;
1061 LPSTR lpszCommandLine;
1062 LPSTR lpszCurrentDirectory;
1063 } RunApplicationEnumStruct, *lpRunApplicationEnumStruct;
1065 /* To be called by RunApplication to find how to invoke the function */
1066 static BOOL CALLBACK RunApplicationA_EnumLocalApplications
1067 ( LPCDPLAPPINFO lpAppInfo,
1068 LPVOID lpContext,
1069 DWORD dwFlags )
1071 lpRunApplicationEnumStruct lpData = (lpRunApplicationEnumStruct)lpContext;
1073 if( IsEqualGUID( &lpAppInfo->guidApplication, &lpData->appGUID ) )
1075 char returnBuffer[200];
1076 DWORD returnType, sizeOfReturnBuffer;
1077 LPCSTR clSubKey = "CommandLine";
1078 LPCSTR cdSubKey = "CurrentDirectory";
1079 LPCSTR fileSubKey = "File";
1080 LPCSTR pathSubKey = "Path";
1082 /* FIXME: Lazy man hack - dplay struct has the present reg key saved */
1084 sizeOfReturnBuffer = 200;
1086 /* Get all the appropriate data from the registry */
1087 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, clSubKey,
1088 NULL, &returnType, (LPBYTE)returnBuffer,
1089 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1091 ERR( ": missing CommandLine registry data member\n" );
1093 else
1095 if ((lpData->lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1096 strcpy( lpData->lpszCommandLine, returnBuffer );
1099 sizeOfReturnBuffer = 200;
1101 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, cdSubKey,
1102 NULL, &returnType, (LPBYTE)returnBuffer,
1103 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1105 ERR( ": missing CurrentDirectory registry data member\n" );
1107 else
1109 if ((lpData->lpszCurrentDirectory = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1110 strcpy( lpData->lpszCurrentDirectory, returnBuffer );
1113 sizeOfReturnBuffer = 200;
1115 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, fileSubKey,
1116 NULL, &returnType, (LPBYTE)returnBuffer,
1117 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1119 ERR( ": missing File registry data member\n" );
1121 else
1123 if ((lpData->lpszFileName = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1124 strcpy( lpData->lpszFileName, returnBuffer );
1127 sizeOfReturnBuffer = 200;
1129 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, pathSubKey,
1130 NULL, &returnType, (LPBYTE)returnBuffer,
1131 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1133 ERR( ": missing Path registry data member\n" );
1135 else
1137 if ((lpData->lpszPath = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1138 strcpy( lpData->lpszPath, returnBuffer );
1141 return FALSE; /* No need to keep going as we found what we wanted */
1144 return TRUE; /* Keep enumerating, haven't found the application yet */
1147 static BOOL DPL_CreateAndSetLobbyHandles( DWORD dwDestProcessId, HANDLE hDestProcess,
1148 LPHANDLE lphStart, LPHANDLE lphDeath,
1149 LPHANDLE lphRead )
1151 /* These are the handles for the created process */
1152 HANDLE hAppStart = 0, hAppDeath = 0, hAppRead = 0;
1153 SECURITY_ATTRIBUTES s_attrib;
1155 s_attrib.nLength = sizeof( s_attrib );
1156 s_attrib.lpSecurityDescriptor = NULL;
1157 s_attrib.bInheritHandle = TRUE;
1159 *lphStart = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
1160 *lphDeath = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
1161 *lphRead = CreateEventW( &s_attrib, TRUE, FALSE, NULL );
1163 if( ( !DuplicateHandle( GetCurrentProcess(), *lphStart,
1164 hDestProcess, &hAppStart,
1165 0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1166 ( !DuplicateHandle( GetCurrentProcess(), *lphDeath,
1167 hDestProcess, &hAppDeath,
1168 0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1169 ( !DuplicateHandle( GetCurrentProcess(), *lphRead,
1170 hDestProcess, &hAppRead,
1171 0, FALSE, DUPLICATE_SAME_ACCESS ) )
1174 if (*lphStart) { CloseHandle(*lphStart); *lphStart = 0; }
1175 if (*lphDeath) { CloseHandle(*lphDeath); *lphDeath = 0; }
1176 if (*lphRead) { CloseHandle(*lphRead); *lphRead = 0; }
1177 /* FIXME: Handle leak... */
1178 ERR( "Unable to dup handles\n" );
1179 return FALSE;
1182 if( !DPLAYX_SetLobbyHandles( dwDestProcessId,
1183 hAppStart, hAppDeath, hAppRead ) )
1185 /* FIXME: Handle leak... */
1186 return FALSE;
1189 return TRUE;
1193 /********************************************************************
1195 * Starts an application and passes to it all the information to
1196 * connect to a session.
1199 static HRESULT WINAPI IDirectPlayLobbyAImpl_RunApplication
1200 ( LPDIRECTPLAYLOBBYA iface,
1201 DWORD dwFlags,
1202 LPDWORD lpdwAppID,
1203 LPDPLCONNECTION lpConn,
1204 HANDLE hReceiveEvent )
1206 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
1207 HRESULT hr;
1208 RunApplicationEnumStruct enumData;
1209 char temp[200];
1210 STARTUPINFOA startupInfo;
1211 PROCESS_INFORMATION newProcessInfo;
1212 LPSTR appName;
1213 DWORD dwSuspendCount;
1214 HANDLE hStart, hDeath, hSettingRead;
1216 TRACE( "(%p)->(0x%08x,%p,%p,%p)\n",
1217 This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1219 if( dwFlags != 0 )
1221 return DPERR_INVALIDPARAMS;
1224 if( DPLAYX_AnyLobbiesWaitingForConnSettings() )
1226 FIXME( "Waiting lobby not being handled correctly\n" );
1229 EnterCriticalSection( &This->unk->DPL_lock );
1231 ZeroMemory( &enumData, sizeof( enumData ) );
1232 enumData.This = This;
1233 enumData.appGUID = lpConn->lpSessionDesc->guidApplication;
1235 /* Our callback function will fill up the enumData structure with all the information
1236 required to start a new process */
1237 IDirectPlayLobby_EnumLocalApplications( iface, RunApplicationA_EnumLocalApplications,
1238 (&enumData), 0 );
1240 /* First the application name */
1241 strcpy( temp, enumData.lpszPath );
1242 strcat( temp, "\\" );
1243 strcat( temp, enumData.lpszFileName );
1244 HeapFree( GetProcessHeap(), 0, enumData.lpszPath );
1245 HeapFree( GetProcessHeap(), 0, enumData.lpszFileName );
1246 if ((appName = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 ))) strcpy( appName, temp );
1248 /* Now the command line */
1249 strcat( temp, " " );
1250 strcat( temp, enumData.lpszCommandLine );
1251 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1252 if ((enumData.lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 )))
1253 strcpy( enumData.lpszCommandLine, temp );
1255 ZeroMemory( &startupInfo, sizeof( startupInfo ) );
1256 startupInfo.cb = sizeof( startupInfo );
1257 /* FIXME: Should any fields be filled in? */
1259 ZeroMemory( &newProcessInfo, sizeof( newProcessInfo ) );
1261 if( !CreateProcessA( appName,
1262 enumData.lpszCommandLine,
1263 NULL,
1264 NULL,
1265 FALSE,
1266 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE | CREATE_SUSPENDED, /* Creation Flags */
1267 NULL,
1268 enumData.lpszCurrentDirectory,
1269 &startupInfo,
1270 &newProcessInfo
1274 ERR( "Failed to create process for app %s\n", appName );
1276 HeapFree( GetProcessHeap(), 0, appName );
1277 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1278 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1280 LeaveCriticalSection( &This->unk->DPL_lock );
1281 return DPERR_CANTCREATEPROCESS;
1284 HeapFree( GetProcessHeap(), 0, appName );
1285 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1286 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1288 /* Reserve this global application id! */
1289 if( !DPLAYX_CreateLobbyApplication( newProcessInfo.dwProcessId ) )
1291 ERR( "Unable to create global application data for 0x%08x\n",
1292 newProcessInfo.dwProcessId );
1295 hr = IDirectPlayLobby_SetConnectionSettings( iface, 0, newProcessInfo.dwProcessId, lpConn );
1297 if( hr != DP_OK )
1299 ERR( "SetConnectionSettings failure %s\n", DPLAYX_HresultToString( hr ) );
1300 LeaveCriticalSection( &This->unk->DPL_lock );
1301 return hr;
1304 /* Setup the handles for application notification */
1305 DPL_CreateAndSetLobbyHandles( newProcessInfo.dwProcessId,
1306 newProcessInfo.hProcess,
1307 &hStart, &hDeath, &hSettingRead );
1309 /* Setup the message thread ID */
1310 This->dpl->dwMsgThread =
1311 CreateLobbyMessageReceptionThread( hReceiveEvent, hStart, hDeath, hSettingRead );
1313 DPLAYX_SetLobbyMsgThreadId( newProcessInfo.dwProcessId, This->dpl->dwMsgThread );
1315 LeaveCriticalSection( &This->unk->DPL_lock );
1317 /* Everything seems to have been set correctly, update the dwAppID */
1318 *lpdwAppID = newProcessInfo.dwProcessId;
1320 /* Unsuspend the process - should return the prev suspension count */
1321 if( ( dwSuspendCount = ResumeThread( newProcessInfo.hThread ) ) != 1 )
1323 ERR( "ResumeThread failed with 0x%08x\n", dwSuspendCount );
1326 return DP_OK;
1329 static HRESULT WINAPI IDirectPlayLobbyWImpl_RunApplication
1330 ( LPDIRECTPLAYLOBBY iface,
1331 DWORD dwFlags,
1332 LPDWORD lpdwAppID,
1333 LPDPLCONNECTION lpConn,
1334 HANDLE hReceiveEvent )
1336 IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1337 FIXME( "(%p)->(0x%08x,%p,%p,%p):stub\n", This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1338 return DPERR_OUTOFMEMORY;
1341 /********************************************************************
1343 * Sends a message between the application and the lobby client.
1344 * All messages are queued until received.
1347 static HRESULT WINAPI IDirectPlayLobbyAImpl_SendLobbyMessage
1348 ( LPDIRECTPLAYLOBBYA iface,
1349 DWORD dwFlags,
1350 DWORD dwAppID,
1351 LPVOID lpData,
1352 DWORD dwDataSize )
1354 FIXME(":stub\n");
1355 return DPERR_OUTOFMEMORY;
1358 static HRESULT WINAPI IDirectPlayLobbyWImpl_SendLobbyMessage
1359 ( LPDIRECTPLAYLOBBY iface,
1360 DWORD dwFlags,
1361 DWORD dwAppID,
1362 LPVOID lpData,
1363 DWORD dwDataSize )
1365 FIXME(":stub\n");
1366 return DPERR_OUTOFMEMORY;
1369 /********************************************************************
1371 * Modifies the DPLCONNECTION structure to contain all information
1372 * needed to start and connect an application.
1375 static HRESULT WINAPI IDirectPlayLobbyWImpl_SetConnectionSettings
1376 ( LPDIRECTPLAYLOBBY iface,
1377 DWORD dwFlags,
1378 DWORD dwAppID,
1379 LPDPLCONNECTION lpConn )
1381 IDirectPlayLobbyWImpl *This = (IDirectPlayLobbyWImpl *)iface;
1382 HRESULT hr;
1384 TRACE("(%p)->(0x%08x,0x%08x,%p)\n", This, dwFlags, dwAppID, lpConn );
1386 EnterCriticalSection( &This->unk->DPL_lock );
1388 hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1390 /* FIXME: Don't think that this is supposed to fail, but the documentation
1391 is somewhat sketchy. I'll try creating a lobby application
1392 for this... */
1393 if( hr == DPERR_NOTLOBBIED )
1395 FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
1396 if( dwAppID == 0 )
1398 dwAppID = GetCurrentProcessId();
1400 DPLAYX_CreateLobbyApplication( dwAppID );
1401 hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1404 LeaveCriticalSection( &This->unk->DPL_lock );
1406 return hr;
1409 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetConnectionSettings
1410 ( LPDIRECTPLAYLOBBYA iface,
1411 DWORD dwFlags,
1412 DWORD dwAppID,
1413 LPDPLCONNECTION lpConn )
1415 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface;
1416 HRESULT hr;
1418 TRACE("(%p)->(0x%08x,0x%08x,%p)\n", This, dwFlags, dwAppID, lpConn );
1420 EnterCriticalSection( &This->unk->DPL_lock );
1422 hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1424 /* FIXME: Don't think that this is supposed to fail, but the documentation
1425 is somewhat sketchy. I'll try creating a lobby application
1426 for this... */
1427 if( hr == DPERR_NOTLOBBIED )
1429 FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
1430 dwAppID = GetCurrentProcessId();
1431 DPLAYX_CreateLobbyApplication( dwAppID );
1432 hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1435 LeaveCriticalSection( &This->unk->DPL_lock );
1437 return hr;
1440 /********************************************************************
1442 * Registers an event that will be set when a lobby message is received.
1445 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetLobbyMessageEvent
1446 ( LPDIRECTPLAYLOBBYA iface,
1447 DWORD dwFlags,
1448 DWORD dwAppID,
1449 HANDLE hReceiveEvent )
1451 FIXME(":stub\n");
1452 return DPERR_OUTOFMEMORY;
1455 static HRESULT WINAPI IDirectPlayLobbyWImpl_SetLobbyMessageEvent
1456 ( LPDIRECTPLAYLOBBY iface,
1457 DWORD dwFlags,
1458 DWORD dwAppID,
1459 HANDLE hReceiveEvent )
1461 FIXME(":stub\n");
1462 return DPERR_OUTOFMEMORY;
1466 /* DPL 2 methods */
1467 static HRESULT WINAPI IDirectPlayLobby2WImpl_CreateCompoundAddress
1468 ( LPDIRECTPLAYLOBBY2 iface,
1469 LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1470 DWORD dwElementCount,
1471 LPVOID lpAddress,
1472 LPDWORD lpdwAddressSize )
1474 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, FALSE );
1477 static HRESULT WINAPI IDirectPlayLobby2AImpl_CreateCompoundAddress
1478 ( LPDIRECTPLAYLOBBY2A iface,
1479 LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1480 DWORD dwElementCount,
1481 LPVOID lpAddress,
1482 LPDWORD lpdwAddressSize )
1484 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, TRUE );
1487 HRESULT DPL_CreateCompoundAddress
1488 ( LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1489 DWORD dwElementCount,
1490 LPVOID lpAddress,
1491 LPDWORD lpdwAddressSize,
1492 BOOL bAnsiInterface )
1494 DWORD dwSizeRequired = 0;
1495 DWORD dwElements;
1496 LPCDPCOMPOUNDADDRESSELEMENT lpOrigElements = lpElements;
1498 TRACE("(%p,0x%08x,%p,%p)\n", lpElements, dwElementCount, lpAddress, lpdwAddressSize );
1500 /* Parameter check */
1501 if( ( lpElements == NULL ) ||
1502 ( dwElementCount == 0 ) /* FIXME: Not sure if this is a failure case */
1505 return DPERR_INVALIDPARAMS;
1508 /* Add the total size chunk */
1509 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DWORD );
1511 /* Calculate the size of the buffer required */
1512 for ( dwElements = dwElementCount; dwElements > 0; --dwElements, ++lpElements )
1514 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1515 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1518 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( GUID );
1520 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1521 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1522 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1525 if( !bAnsiInterface )
1527 ERR( "Ansi GUIDs used for unicode interface\n" );
1528 return DPERR_INVALIDFLAGS;
1531 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize;
1533 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1534 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1535 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1538 if( bAnsiInterface )
1540 ERR( "Unicode GUIDs used for ansi interface\n" );
1541 return DPERR_INVALIDFLAGS;
1544 FIXME( "Right size for unicode interface?\n" );
1545 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize * sizeof( WCHAR );
1547 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1549 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( WORD );
1551 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1553 FIXME( "Right size for unicode interface?\n" );
1554 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DPCOMPORTADDRESS ); /* FIXME: Right size? */
1556 else
1558 ERR( "Unknown GUID %s\n", debugstr_guid(&lpElements->guidDataType) );
1559 return DPERR_INVALIDFLAGS;
1563 /* The user wants to know how big a buffer to allocate for us */
1564 if( ( lpAddress == NULL ) ||
1565 ( *lpdwAddressSize < dwSizeRequired )
1568 *lpdwAddressSize = dwSizeRequired;
1569 return DPERR_BUFFERTOOSMALL;
1572 /* Add the total size chunk */
1574 LPDPADDRESS lpdpAddress = lpAddress;
1576 lpdpAddress->guidDataType = DPAID_TotalSize;
1577 lpdpAddress->dwDataSize = sizeof( DWORD );
1578 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1580 *(LPDWORD)lpAddress = dwSizeRequired;
1581 lpAddress = (char *) lpAddress + sizeof( DWORD );
1584 /* Calculate the size of the buffer required */
1585 for( dwElements = dwElementCount, lpElements = lpOrigElements;
1586 dwElements > 0;
1587 --dwElements, ++lpElements )
1589 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1590 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1593 LPDPADDRESS lpdpAddress = lpAddress;
1595 lpdpAddress->guidDataType = lpElements->guidDataType;
1596 lpdpAddress->dwDataSize = sizeof( GUID );
1597 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1599 CopyMemory( lpAddress, lpElements->lpData, sizeof( GUID ) );
1600 lpAddress = (char *) lpAddress + sizeof( GUID );
1602 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1603 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1604 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1607 LPDPADDRESS lpdpAddress = lpAddress;
1609 lpdpAddress->guidDataType = lpElements->guidDataType;
1610 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1611 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1613 lstrcpynA( lpAddress, lpElements->lpData, lpElements->dwDataSize );
1614 lpAddress = (char *) lpAddress + lpElements->dwDataSize;
1616 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1617 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1618 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1621 LPDPADDRESS lpdpAddress = lpAddress;
1623 lpdpAddress->guidDataType = lpElements->guidDataType;
1624 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1625 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1627 lstrcpynW( lpAddress, lpElements->lpData, lpElements->dwDataSize );
1628 lpAddress = (char *) lpAddress + lpElements->dwDataSize * sizeof( WCHAR );
1630 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1632 LPDPADDRESS lpdpAddress = lpAddress;
1634 lpdpAddress->guidDataType = lpElements->guidDataType;
1635 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1636 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1638 *((LPWORD)lpAddress) = *((LPWORD)lpElements->lpData);
1639 lpAddress = (char *) lpAddress + sizeof( WORD );
1641 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1643 LPDPADDRESS lpdpAddress = lpAddress;
1645 lpdpAddress->guidDataType = lpElements->guidDataType;
1646 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1647 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1649 CopyMemory( lpAddress, lpElements->lpData, sizeof( DPADDRESS ) );
1650 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1654 return DP_OK;
1657 /* DPL 3 methods */
1659 static HRESULT WINAPI IDirectPlayLobby3WImpl_ConnectEx
1660 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFIID riid,
1661 LPVOID* lplpDP, IUnknown* pUnk )
1663 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface ;
1664 return DPL_ConnectEx( This, dwFlags, riid, lplpDP, pUnk );
1667 static HRESULT WINAPI IDirectPlayLobby3AImpl_ConnectEx
1668 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, REFIID riid,
1669 LPVOID* lplpDP, IUnknown* pUnk )
1671 IDirectPlayLobbyAImpl *This = (IDirectPlayLobbyAImpl *)iface ;
1672 return DPL_ConnectEx( This, dwFlags, riid, lplpDP, pUnk );
1675 static HRESULT WINAPI IDirectPlayLobby3WImpl_RegisterApplication
1676 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
1678 FIXME(":stub\n");
1679 return DP_OK;
1682 static HRESULT WINAPI IDirectPlayLobby3AImpl_RegisterApplication
1683 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
1685 FIXME(":stub\n");
1686 return DP_OK;
1689 static HRESULT WINAPI IDirectPlayLobby3WImpl_UnregisterApplication
1690 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFGUID lpAppDesc )
1692 FIXME(":stub\n");
1693 return DP_OK;
1696 static HRESULT WINAPI IDirectPlayLobby3AImpl_UnregisterApplication
1697 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, REFGUID lpAppDesc )
1699 FIXME(":stub\n");
1700 return DP_OK;
1703 static HRESULT WINAPI IDirectPlayLobby3WImpl_WaitForConnectionSettings
1704 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags )
1706 HRESULT hr = DP_OK;
1707 BOOL bStartWait = (dwFlags & DPLWAIT_CANCEL) ? FALSE : TRUE;
1709 TRACE( "(%p)->(0x%08x)\n", iface, dwFlags );
1711 if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
1713 /* FIXME: What is the correct error return code? */
1714 hr = DPERR_NOTLOBBIED;
1717 return hr;
1720 static HRESULT WINAPI IDirectPlayLobby3AImpl_WaitForConnectionSettings
1721 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags )
1723 HRESULT hr = DP_OK;
1724 BOOL bStartWait = (dwFlags & DPLWAIT_CANCEL) ? FALSE : TRUE;
1726 TRACE( "(%p)->(0x%08x)\n", iface, dwFlags );
1728 if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
1730 /* FIXME: What is the correct error return code? */
1731 hr = DPERR_NOTLOBBIED;
1734 return hr;
1738 /* Virtual Table definitions for DPL{1,2,3}{A,W} */
1740 /* Note: Hack so we can reuse the old functions without compiler warnings */
1741 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1742 # define XCAST(fun) (typeof(directPlayLobbyAVT.fun))
1743 #else
1744 # define XCAST(fun) (void*)
1745 #endif
1747 /* Direct Play Lobby 1 (ascii) Virtual Table for methods */
1748 /* All lobby 1 methods are exactly the same except QueryInterface */
1749 static const IDirectPlayLobbyVtbl directPlayLobbyAVT =
1752 XCAST(QueryInterface)DPL_QueryInterface,
1753 XCAST(AddRef)DPL_AddRef,
1754 XCAST(Release)DPL_Release,
1756 IDirectPlayLobbyAImpl_Connect,
1757 IDirectPlayLobbyAImpl_CreateAddress,
1758 IDirectPlayLobbyAImpl_EnumAddress,
1759 IDirectPlayLobbyAImpl_EnumAddressTypes,
1760 IDirectPlayLobbyAImpl_EnumLocalApplications,
1761 IDirectPlayLobbyAImpl_GetConnectionSettings,
1762 IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1763 IDirectPlayLobbyAImpl_RunApplication,
1764 IDirectPlayLobbyAImpl_SendLobbyMessage,
1765 IDirectPlayLobbyAImpl_SetConnectionSettings,
1766 IDirectPlayLobbyAImpl_SetLobbyMessageEvent
1768 #undef XCAST
1771 /* Note: Hack so we can reuse the old functions without compiler warnings */
1772 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1773 # define XCAST(fun) (typeof(directPlayLobbyWVT.fun))
1774 #else
1775 # define XCAST(fun) (void*)
1776 #endif
1778 /* Direct Play Lobby 1 (unicode) Virtual Table for methods */
1779 static const IDirectPlayLobbyVtbl directPlayLobbyWVT =
1782 XCAST(QueryInterface)DPL_QueryInterface,
1783 XCAST(AddRef)DPL_AddRef,
1784 XCAST(Release)DPL_Release,
1786 IDirectPlayLobbyWImpl_Connect,
1787 IDirectPlayLobbyWImpl_CreateAddress,
1788 IDirectPlayLobbyWImpl_EnumAddress,
1789 IDirectPlayLobbyWImpl_EnumAddressTypes,
1790 IDirectPlayLobbyWImpl_EnumLocalApplications,
1791 IDirectPlayLobbyWImpl_GetConnectionSettings,
1792 IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1793 IDirectPlayLobbyWImpl_RunApplication,
1794 IDirectPlayLobbyWImpl_SendLobbyMessage,
1795 IDirectPlayLobbyWImpl_SetConnectionSettings,
1796 IDirectPlayLobbyWImpl_SetLobbyMessageEvent
1798 #undef XCAST
1800 /* Note: Hack so we can reuse the old functions without compiler warnings */
1801 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1802 # define XCAST(fun) (typeof(directPlayLobby2AVT.fun))
1803 #else
1804 # define XCAST(fun) (void*)
1805 #endif
1807 /* Direct Play Lobby 2 (ascii) Virtual Table for methods */
1808 static const IDirectPlayLobby2Vtbl directPlayLobby2AVT =
1811 XCAST(QueryInterface)DPL_QueryInterface,
1812 XCAST(AddRef)DPL_AddRef,
1813 XCAST(Release)DPL_Release,
1815 XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
1816 XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
1817 XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
1818 XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
1819 XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
1820 XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
1821 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1822 XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
1823 XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
1824 XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
1825 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,
1827 IDirectPlayLobby2AImpl_CreateCompoundAddress
1829 #undef XCAST
1831 /* Note: Hack so we can reuse the old functions without compiler warnings */
1832 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1833 # define XCAST(fun) (typeof(directPlayLobby2WVT.fun))
1834 #else
1835 # define XCAST(fun) (void*)
1836 #endif
1838 /* Direct Play Lobby 2 (unicode) Virtual Table for methods */
1839 static const IDirectPlayLobby2Vtbl directPlayLobby2WVT =
1842 XCAST(QueryInterface)DPL_QueryInterface,
1843 XCAST(AddRef)DPL_AddRef,
1844 XCAST(Release)DPL_Release,
1846 XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
1847 XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
1848 XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
1849 XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
1850 XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
1851 XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
1852 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1853 XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
1854 XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
1855 XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
1856 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,
1858 IDirectPlayLobby2WImpl_CreateCompoundAddress
1860 #undef XCAST
1862 /* Direct Play Lobby 3 (ascii) Virtual Table for methods */
1864 /* Note: Hack so we can reuse the old functions without compiler warnings */
1865 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1866 # define XCAST(fun) (typeof(directPlayLobby3AVT.fun))
1867 #else
1868 # define XCAST(fun) (void*)
1869 #endif
1871 static const IDirectPlayLobby3Vtbl directPlayLobby3AVT =
1873 XCAST(QueryInterface)DPL_QueryInterface,
1874 XCAST(AddRef)DPL_AddRef,
1875 XCAST(Release)DPL_Release,
1877 XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
1878 XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
1879 XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
1880 XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
1881 XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
1882 XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
1883 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1884 XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
1885 XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
1886 XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
1887 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,
1889 XCAST(CreateCompoundAddress)IDirectPlayLobby2AImpl_CreateCompoundAddress,
1891 IDirectPlayLobby3AImpl_ConnectEx,
1892 IDirectPlayLobby3AImpl_RegisterApplication,
1893 IDirectPlayLobby3AImpl_UnregisterApplication,
1894 IDirectPlayLobby3AImpl_WaitForConnectionSettings
1896 #undef XCAST
1898 /* Direct Play Lobby 3 (unicode) Virtual Table for methods */
1900 /* Note: Hack so we can reuse the old functions without compiler warnings */
1901 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1902 # define XCAST(fun) (typeof(directPlayLobby3WVT.fun))
1903 #else
1904 # define XCAST(fun) (void*)
1905 #endif
1907 static const IDirectPlayLobby3Vtbl directPlayLobby3WVT =
1909 XCAST(QueryInterface)DPL_QueryInterface,
1910 XCAST(AddRef)DPL_AddRef,
1911 XCAST(Release)DPL_Release,
1913 XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
1914 XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
1915 XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
1916 XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
1917 XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
1918 XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
1919 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1920 XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
1921 XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
1922 XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
1923 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,
1925 XCAST(CreateCompoundAddress)IDirectPlayLobby2WImpl_CreateCompoundAddress,
1927 IDirectPlayLobby3WImpl_ConnectEx,
1928 IDirectPlayLobby3WImpl_RegisterApplication,
1929 IDirectPlayLobby3WImpl_UnregisterApplication,
1930 IDirectPlayLobby3WImpl_WaitForConnectionSettings
1932 #undef XCAST
1935 /*********************************************************
1937 * Direct Play Lobby Interface Implementation
1939 *********************************************************/
1941 /***************************************************************************
1942 * DirectPlayLobbyCreateA (DPLAYX.4)
1945 HRESULT WINAPI DirectPlayLobbyCreateA( LPGUID lpGUIDDSP,
1946 LPDIRECTPLAYLOBBYA *lplpDPL,
1947 IUnknown *lpUnk,
1948 LPVOID lpData,
1949 DWORD dwDataSize )
1951 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08x\n",
1952 lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);
1954 /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
1955 * equal 0. These fields are mostly for future expansion.
1957 if ( lpGUIDDSP || lpData || dwDataSize )
1959 *lplpDPL = NULL;
1960 return DPERR_INVALIDPARAMS;
1963 if( lpUnk )
1965 *lplpDPL = NULL;
1966 ERR("Bad parameters!\n" );
1967 return CLASS_E_NOAGGREGATION;
1970 return DPL_CreateInterface( &IID_IDirectPlayLobbyA, (void**)lplpDPL );
1973 /***************************************************************************
1974 * DirectPlayLobbyCreateW (DPLAYX.5)
1977 HRESULT WINAPI DirectPlayLobbyCreateW( LPGUID lpGUIDDSP,
1978 LPDIRECTPLAYLOBBY *lplpDPL,
1979 IUnknown *lpUnk,
1980 LPVOID lpData,
1981 DWORD dwDataSize )
1983 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08x\n",
1984 lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);
1986 /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
1987 * equal 0. These fields are mostly for future expansion.
1989 if ( lpGUIDDSP || lpData || dwDataSize )
1991 *lplpDPL = NULL;
1992 ERR("Bad parameters!\n" );
1993 return DPERR_INVALIDPARAMS;
1996 if( lpUnk )
1998 *lplpDPL = NULL;
1999 ERR("Bad parameters!\n" );
2000 return CLASS_E_NOAGGREGATION;
2003 return DPL_CreateInterface( &IID_IDirectPlayLobby, (void**)lplpDPL );