Release 20030408.
[wine/gsoc-2012-control.git] / dlls / dplayx / dplobby.c
blob8c04a0f38d7fdaaaa08a05dfa271e028ceab7f07
1 /* Direct Play Lobby 2 & 3 Implementation
3 * Copyright 1998,1999,2000 - Peter Hunnisett
5 * <presently under construction - contact hunnise@nortelnetworks.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <string.h>
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
25 #include "windef.h"
26 #include "winerror.h"
27 #include "winreg.h"
28 #include "winnls.h"
29 #include "wine/debug.h"
31 #include "dplobby.h"
32 #include "dpinit.h"
33 #include "dplayx_global.h"
34 #include "dplayx_messages.h"
35 #include "dplayx_queue.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 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 WINAPI DPL_ConnectEx( IDirectPlayLobbyAImpl* This,
62 DWORD dwFlags, REFIID riid,
63 LPVOID* lplpDP, IUnknown* pUnk );
65 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 derefernce is that I wanted to
74 * have the same structure for all types of objects without having to do
75 * alot 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 ULONG 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 ULONG ulInterfaceRef; \
114 DirectPlayLobbyIUnknownData* unk; \
115 DirectPlayLobbyData* dpl; \
116 DirectPlayLobby2Data* dpl2; \
117 DirectPlayLobby3Data* dpl3;
119 struct IDirectPlayLobbyImpl
121 ICOM_VFIELD(IDirectPlayLobby);
122 DPL_IMPL_FIELDS
125 struct IDirectPlayLobby2Impl
127 ICOM_VFIELD(IDirectPlayLobby2);
128 DPL_IMPL_FIELDS
131 struct IDirectPlayLobby3Impl
133 ICOM_VFIELD(IDirectPlayLobby3);
134 DPL_IMPL_FIELDS
138 /* Forward declarations of virtual tables */
139 static ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyWVT;
140 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2WVT;
141 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3WVT;
143 static ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyAVT;
144 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2AVT;
145 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3AVT;
150 static BOOL DPL_CreateIUnknown( LPVOID lpDPL )
152 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
154 This->unk = (DirectPlayLobbyIUnknownData*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
155 sizeof( *(This->unk) ) );
156 if ( This->unk == NULL )
158 return FALSE;
161 InitializeCriticalSection( &This->unk->DPL_lock );
163 return TRUE;
166 static BOOL DPL_DestroyIUnknown( LPVOID lpDPL )
168 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
170 DeleteCriticalSection( &This->unk->DPL_lock );
171 HeapFree( GetProcessHeap(), 0, This->unk );
173 return TRUE;
176 static BOOL DPL_CreateLobby1( LPVOID lpDPL )
178 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
180 This->dpl = (DirectPlayLobbyData*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
181 sizeof( *(This->dpl) ) );
182 if ( This->dpl == NULL )
184 return FALSE;
187 DPQ_INIT( This->dpl->msgs );
189 return TRUE;
192 static BOOL DPL_DestroyLobby1( LPVOID lpDPL )
194 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
196 if( This->dpl->dwMsgThread )
198 FIXME( "Should kill the msg thread\n" );
201 DPQ_DELETEQ( This->dpl->msgs, msgs, LPDPLMSG, cbDeleteElemFromHeap );
203 /* Delete the contents */
204 HeapFree( GetProcessHeap(), 0, This->dpl );
206 return TRUE;
209 static BOOL DPL_CreateLobby2( LPVOID lpDPL )
211 ICOM_THIS(IDirectPlayLobby2AImpl,lpDPL);
213 This->dpl2 = (DirectPlayLobby2Data*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
214 sizeof( *(This->dpl2) ) );
215 if ( This->dpl2 == NULL )
217 return FALSE;
220 return TRUE;
223 static BOOL DPL_DestroyLobby2( LPVOID lpDPL )
225 ICOM_THIS(IDirectPlayLobby2AImpl,lpDPL);
227 HeapFree( GetProcessHeap(), 0, This->dpl2 );
229 return TRUE;
232 static BOOL DPL_CreateLobby3( LPVOID lpDPL )
234 ICOM_THIS(IDirectPlayLobby3AImpl,lpDPL);
236 This->dpl3 = (DirectPlayLobby3Data*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
237 sizeof( *(This->dpl3) ) );
238 if ( This->dpl3 == NULL )
240 return FALSE;
243 return TRUE;
246 static BOOL DPL_DestroyLobby3( LPVOID lpDPL )
248 ICOM_THIS(IDirectPlayLobby3AImpl,lpDPL);
250 HeapFree( GetProcessHeap(), 0, This->dpl3 );
252 return TRUE;
256 /* The COM interface for upversioning an interface
257 * We've been given a GUID (riid) and we need to replace the present
258 * interface with that of the requested interface.
260 * Snip from some Microsoft document:
261 * There are four requirements for implementations of QueryInterface (In these
262 * cases, "must succeed" means "must succeed barring catastrophic failure."):
264 * * The set of interfaces accessible on an object through
265 * IUnknown::QueryInterface must be static, not dynamic. This means that
266 * if a call to QueryInterface for a pointer to a specified interface
267 * succeeds the first time, it must succeed again, and if it fails the
268 * first time, it must fail on all subsequent queries.
269 * * It must be symmetric ~W if a client holds a pointer to an interface on
270 * an object, and queries for that interface, the call must succeed.
271 * * It must be reflexive ~W if a client holding a pointer to one interface
272 * queries successfully for another, a query through the obtained pointer
273 * for the first interface must succeed.
274 * * It must be transitive ~W if a client holding a pointer to one interface
275 * queries successfully for a second, and through that pointer queries
276 * successfully for a third interface, a query for the first interface
277 * through the pointer for the third interface must succeed.
279 extern
280 HRESULT DPL_CreateInterface
281 ( REFIID riid, LPVOID* ppvObj )
283 TRACE( " for %s\n", debugstr_guid( riid ) );
285 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
286 sizeof( IDirectPlayLobbyWImpl ) );
288 if( *ppvObj == NULL )
290 return DPERR_OUTOFMEMORY;
293 if( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
295 ICOM_THIS(IDirectPlayLobbyWImpl,*ppvObj);
296 ICOM_VTBL(This) = &directPlayLobbyWVT;
298 else if( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
300 ICOM_THIS(IDirectPlayLobbyAImpl,*ppvObj);
301 ICOM_VTBL(This) = &directPlayLobbyAVT;
303 else if( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
305 ICOM_THIS(IDirectPlayLobby2WImpl,*ppvObj);
306 ICOM_VTBL(This) = &directPlayLobby2WVT;
308 else if( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
310 ICOM_THIS(IDirectPlayLobby2AImpl,*ppvObj);
311 ICOM_VTBL(This) = &directPlayLobby2AVT;
313 else if( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
315 ICOM_THIS(IDirectPlayLobby3WImpl,*ppvObj);
316 ICOM_VTBL(This) = &directPlayLobby3WVT;
318 else if( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
320 ICOM_THIS(IDirectPlayLobby3AImpl,*ppvObj);
321 ICOM_VTBL(This) = &directPlayLobby3AVT;
323 else
325 /* Unsupported interface */
326 HeapFree( GetProcessHeap(), 0, *ppvObj );
327 *ppvObj = NULL;
329 return E_NOINTERFACE;
332 /* Initialize it */
333 if ( DPL_CreateIUnknown( *ppvObj ) &&
334 DPL_CreateLobby1( *ppvObj ) &&
335 DPL_CreateLobby2( *ppvObj ) &&
336 DPL_CreateLobby3( *ppvObj )
339 IDirectPlayLobby_AddRef( (LPDIRECTPLAYLOBBY)*ppvObj );
340 return S_OK;
343 /* Initialize failed, destroy it */
344 DPL_DestroyLobby3( *ppvObj );
345 DPL_DestroyLobby2( *ppvObj );
346 DPL_DestroyLobby1( *ppvObj );
347 DPL_DestroyIUnknown( *ppvObj );
348 HeapFree( GetProcessHeap(), 0, *ppvObj );
350 *ppvObj = NULL;
351 return DPERR_NOMEMORY;
354 static HRESULT WINAPI DPL_QueryInterface
355 ( LPDIRECTPLAYLOBBYA iface,
356 REFIID riid,
357 LPVOID* ppvObj )
359 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
360 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
362 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
363 sizeof( *This ) );
365 if( *ppvObj == NULL )
367 return DPERR_OUTOFMEMORY;
370 CopyMemory( *ppvObj, This, sizeof( *This ) );
371 (*(IDirectPlayLobbyAImpl**)ppvObj)->ulInterfaceRef = 0;
373 if( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
375 ICOM_THIS(IDirectPlayLobbyWImpl,*ppvObj);
376 ICOM_VTBL(This) = &directPlayLobbyWVT;
378 else if( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
380 ICOM_THIS(IDirectPlayLobbyAImpl,*ppvObj);
381 ICOM_VTBL(This) = &directPlayLobbyAVT;
383 else if( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
385 ICOM_THIS(IDirectPlayLobby2WImpl,*ppvObj);
386 ICOM_VTBL(This) = &directPlayLobby2WVT;
388 else if( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
390 ICOM_THIS(IDirectPlayLobby2AImpl,*ppvObj);
391 ICOM_VTBL(This) = &directPlayLobby2AVT;
393 else if( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
395 ICOM_THIS(IDirectPlayLobby3WImpl,*ppvObj);
396 ICOM_VTBL(This) = &directPlayLobby3WVT;
398 else if( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
400 ICOM_THIS(IDirectPlayLobby3AImpl,*ppvObj);
401 ICOM_VTBL(This) = &directPlayLobby3AVT;
403 else
405 /* Unsupported interface */
406 HeapFree( GetProcessHeap(), 0, *ppvObj );
407 *ppvObj = NULL;
409 return E_NOINTERFACE;
412 IDirectPlayLobby_AddRef( (LPDIRECTPLAYLOBBY)*ppvObj );
414 return S_OK;
418 * Simple procedure. Just increment the reference count to this
419 * structure and return the new reference count.
421 static ULONG WINAPI DPL_AddRef
422 ( LPDIRECTPLAYLOBBY iface )
424 ULONG ulInterfaceRefCount, ulObjRefCount;
425 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
427 ulObjRefCount = InterlockedIncrement( &This->unk->ulObjRef );
428 ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );
430 TRACE( "ref count incremented to %lu:%lu for %p\n",
431 ulInterfaceRefCount, ulObjRefCount, This );
433 return ulObjRefCount;
437 * Simple COM procedure. Decrease the reference count to this object.
438 * If the object no longer has any reference counts, free up the associated
439 * memory.
441 static ULONG WINAPI DPL_Release
442 ( LPDIRECTPLAYLOBBYA iface )
444 ULONG ulInterfaceRefCount, ulObjRefCount;
445 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
447 ulObjRefCount = InterlockedDecrement( &This->unk->ulObjRef );
448 ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );
450 TRACE( "ref count decremented to %lu:%lu for %p\n",
451 ulInterfaceRefCount, ulObjRefCount, This );
453 /* Deallocate if this is the last reference to the object */
454 if( ulObjRefCount == 0 )
456 DPL_DestroyLobby3( This );
457 DPL_DestroyLobby2( This );
458 DPL_DestroyLobby1( This );
459 DPL_DestroyIUnknown( This );
462 if( ulInterfaceRefCount == 0 )
464 HeapFree( GetProcessHeap(), 0, This );
467 return ulInterfaceRefCount;
471 /********************************************************************
473 * Connects an application to the session specified by the DPLCONNECTION
474 * structure currently stored with the DirectPlayLobby object.
476 * Returns a IDirectPlay interface.
479 static HRESULT WINAPI DPL_ConnectEx
480 ( IDirectPlayLobbyAImpl* This,
481 DWORD dwFlags,
482 REFIID riid,
483 LPVOID* lplpDP,
484 IUnknown* pUnk)
486 HRESULT hr;
487 DWORD dwOpenFlags = 0;
488 DWORD dwConnSize = 0;
489 LPDPLCONNECTION lpConn;
491 FIXME("(%p)->(0x%08lx,%p,%p): semi stub\n", This, dwFlags, lplpDP, pUnk );
493 if( pUnk )
495 return DPERR_INVALIDPARAMS;
498 /* Backwards compatibility */
499 if( dwFlags == 0 )
501 dwFlags = DPCONNECT_RETURNSTATUS;
504 /* Create the DirectPlay interface */
505 if( ( hr = DP_CreateInterface( riid, lplpDP ) ) != DP_OK )
507 ERR( "error creating interface for %s:%s.\n",
508 debugstr_guid( riid ), DPLAYX_HresultToString( hr ) );
509 return hr;
512 /* FIXME: Is it safe/correct to use appID of 0? */
513 hr = IDirectPlayLobby_GetConnectionSettings( (LPDIRECTPLAYLOBBY)This,
514 0, NULL, &dwConnSize );
515 if( hr != DPERR_BUFFERTOOSMALL )
517 return hr;
520 lpConn = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwConnSize );
522 if( lpConn == NULL )
524 return DPERR_NOMEMORY;
527 /* FIXME: Is it safe/correct to use appID of 0? */
528 hr = IDirectPlayLobby_GetConnectionSettings( (LPDIRECTPLAYLOBBY)This,
529 0, lpConn, &dwConnSize );
530 if( FAILED( hr ) )
532 HeapFree( GetProcessHeap(), 0, lpConn );
533 return hr;
536 #if 0
537 /* - Need to call IDirectPlay::EnumConnections with the service provider to get that good information
538 * - Need to call CreateAddress to create the lpConnection param for IDirectPlay::InitializeConnection
539 * - Call IDirectPlay::InitializeConnection
542 /* Now initialize the Service Provider */
543 hr = IDirectPlayX_InitializeConnection( (*(LPDIRECTPLAY2*)lplpDP),
544 #endif
547 /* Setup flags to pass into DirectPlay::Open */
548 if( dwFlags & DPCONNECT_RETURNSTATUS )
550 dwOpenFlags |= DPOPEN_RETURNSTATUS;
552 dwOpenFlags |= lpConn->dwFlags;
554 hr = IDirectPlayX_Open( (*(LPDIRECTPLAY2*)lplpDP), lpConn->lpSessionDesc,
555 dwOpenFlags );
557 HeapFree( GetProcessHeap(), 0, lpConn );
559 return hr;
562 static HRESULT WINAPI IDirectPlayLobbyAImpl_Connect
563 ( LPDIRECTPLAYLOBBYA iface,
564 DWORD dwFlags,
565 LPDIRECTPLAY2A* lplpDP,
566 IUnknown* pUnk)
568 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
569 return DPL_ConnectEx( This, dwFlags, &IID_IDirectPlay2A,
570 (LPVOID)lplpDP, pUnk );
573 static HRESULT WINAPI IDirectPlayLobbyWImpl_Connect
574 ( LPDIRECTPLAYLOBBY iface,
575 DWORD dwFlags,
576 LPDIRECTPLAY2* lplpDP,
577 IUnknown* pUnk)
579 ICOM_THIS(IDirectPlayLobbyAImpl,iface); /* Yes cast to A */
580 return DPL_ConnectEx( This, dwFlags, &IID_IDirectPlay2,
581 (LPVOID)lplpDP, pUnk );
584 /********************************************************************
586 * Creates a DirectPlay Address, given a service provider-specific network
587 * address.
588 * Returns an address contains the globally unique identifier
589 * (GUID) of the service provider and data that the service provider can
590 * interpret as a network address.
592 * NOTE: It appears that this method is supposed to be really really stupid
593 * with no error checking on the contents.
595 static HRESULT WINAPI IDirectPlayLobbyAImpl_CreateAddress
596 ( LPDIRECTPLAYLOBBYA iface,
597 REFGUID guidSP,
598 REFGUID guidDataType,
599 LPCVOID lpData,
600 DWORD dwDataSize,
601 LPVOID lpAddress,
602 LPDWORD lpdwAddressSize )
604 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
605 lpAddress, lpdwAddressSize, TRUE );
608 static HRESULT WINAPI IDirectPlayLobbyWImpl_CreateAddress
609 ( LPDIRECTPLAYLOBBY iface,
610 REFGUID guidSP,
611 REFGUID guidDataType,
612 LPCVOID lpData,
613 DWORD dwDataSize,
614 LPVOID lpAddress,
615 LPDWORD lpdwAddressSize )
617 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
618 lpAddress, lpdwAddressSize, FALSE );
621 HRESULT DPL_CreateAddress(
622 REFGUID guidSP,
623 REFGUID guidDataType,
624 LPCVOID lpData,
625 DWORD dwDataSize,
626 LPVOID lpAddress,
627 LPDWORD lpdwAddressSize,
628 BOOL bAnsiInterface )
630 const DWORD dwNumAddElements = 2; /* Service Provide & address data type */
631 DPCOMPOUNDADDRESSELEMENT addressElements[ 2 /* dwNumAddElements */ ];
633 TRACE( "(%p)->(%p,%p,0x%08lx,%p,%p,%d)\n", guidSP, guidDataType, lpData, dwDataSize,
634 lpAddress, lpdwAddressSize, bAnsiInterface );
636 addressElements[ 0 ].guidDataType = DPAID_ServiceProvider;
637 addressElements[ 0 ].dwDataSize = sizeof( GUID );
638 addressElements[ 0 ].lpData = (LPVOID)guidSP;
640 addressElements[ 1 ].guidDataType = *guidDataType;
641 addressElements[ 1 ].dwDataSize = dwDataSize;
642 addressElements[ 1 ].lpData = (LPVOID)lpData;
644 /* Call CreateCompoundAddress to cut down on code.
645 NOTE: We can do this because we don't support DPL 1 interfaces! */
646 return DPL_CreateCompoundAddress( addressElements, dwNumAddElements,
647 lpAddress, lpdwAddressSize, bAnsiInterface );
652 /********************************************************************
654 * Parses out chunks from the DirectPlay Address buffer by calling the
655 * given callback function, with lpContext, for each of the chunks.
658 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddress
659 ( LPDIRECTPLAYLOBBYA iface,
660 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
661 LPCVOID lpAddress,
662 DWORD dwAddressSize,
663 LPVOID lpContext )
665 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
667 TRACE("(%p)->(%p,%p,0x%08lx,%p)\n", This, lpEnumAddressCallback, lpAddress,
668 dwAddressSize, lpContext );
670 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
673 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddress
674 ( LPDIRECTPLAYLOBBY iface,
675 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
676 LPCVOID lpAddress,
677 DWORD dwAddressSize,
678 LPVOID lpContext )
680 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
682 TRACE("(%p)->(%p,%p,0x%08lx,%p)\n", This, lpEnumAddressCallback, lpAddress,
683 dwAddressSize, lpContext );
685 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
688 extern HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
689 DWORD dwAddressSize, LPVOID lpContext )
691 DWORD dwTotalSizeEnumerated = 0;
693 /* FIXME: First chunk is always the total size chunk - Should we report it? */
695 while ( dwTotalSizeEnumerated < dwAddressSize )
697 LPDPADDRESS lpElements = (LPDPADDRESS)lpAddress;
698 DWORD dwSizeThisEnumeration;
700 /* Invoke the enum method. If false is returned, stop enumeration */
701 if ( !lpEnumAddressCallback( &lpElements->guidDataType,
702 lpElements->dwDataSize,
703 (BYTE*)lpElements + sizeof( DPADDRESS ),
704 lpContext ) )
706 break;
709 dwSizeThisEnumeration = sizeof( DPADDRESS ) + lpElements->dwDataSize;
710 lpAddress = (BYTE*) lpAddress + dwSizeThisEnumeration;
711 dwTotalSizeEnumerated += dwSizeThisEnumeration;
714 return DP_OK;
717 /********************************************************************
719 * Enumerates all the address types that a given service provider needs to
720 * build the DirectPlay Address.
723 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddressTypes
724 ( LPDIRECTPLAYLOBBYA iface,
725 LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
726 REFGUID guidSP,
727 LPVOID lpContext,
728 DWORD dwFlags )
730 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
732 HKEY hkResult;
733 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Service Providers";
734 DWORD dwIndex, sizeOfSubKeyName=50;
735 char subKeyName[51];
736 FILETIME filetime;
738 TRACE(" (%p)->(%p,%p,%p,0x%08lx)\n", This, lpEnumAddressTypeCallback, guidSP, lpContext, dwFlags );
740 if( dwFlags != 0 )
742 return DPERR_INVALIDPARAMS;
745 if( !lpEnumAddressTypeCallback || !*lpEnumAddressTypeCallback )
747 return DPERR_INVALIDPARAMS;
750 if( guidSP == NULL )
752 return DPERR_INVALIDOBJECT;
755 /* Need to loop over the service providers in the registry */
756 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
757 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
759 /* Hmmm. Does this mean that there are no service providers? */
760 ERR(": no service providers?\n");
761 return DP_OK;
764 /* Traverse all the service providers we have available */
765 for( dwIndex=0;
766 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
767 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
768 ++dwIndex, sizeOfSubKeyName=50 )
771 HKEY hkServiceProvider, hkServiceProviderAt;
772 GUID serviceProviderGUID;
773 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
774 char atSubKey[51];
775 char returnBuffer[51];
776 WCHAR buff[51];
777 DWORD dwAtIndex;
778 LPSTR atKey = "Address Types";
779 LPSTR guidDataSubKey = "Guid";
780 FILETIME filetime;
783 TRACE(" this time through: %s\n", subKeyName );
785 /* Get a handle for this particular service provider */
786 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
787 &hkServiceProvider ) != ERROR_SUCCESS )
789 ERR(": what the heck is going on?\n" );
790 continue;
793 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
794 NULL, &returnTypeGUID, returnBuffer,
795 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
797 ERR(": missing GUID registry data members\n" );
798 continue;
801 /* FIXME: Check return types to ensure we're interpreting data right */
802 MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff)/sizeof(WCHAR) );
803 CLSIDFromString( (LPCOLESTR)buff, &serviceProviderGUID );
804 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
806 /* Determine if this is the Service Provider that the user asked for */
807 if( !IsEqualGUID( &serviceProviderGUID, guidSP ) )
809 continue;
812 /* Get a handle for this particular service provider */
813 if( RegOpenKeyExA( hkServiceProvider, atKey, 0, KEY_READ,
814 &hkServiceProviderAt ) != ERROR_SUCCESS )
816 TRACE(": No Address Types registry data sub key/members\n" );
817 break;
820 /* Traverse all the address type we have available */
821 for( dwAtIndex=0;
822 RegEnumKeyExA( hkServiceProviderAt, dwAtIndex, atSubKey, &sizeOfSubKeyName,
823 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
824 ++dwAtIndex, sizeOfSubKeyName=50 )
826 TRACE( "Found Address Type GUID %s\n", atSubKey );
828 /* FIXME: Check return types to ensure we're interpreting data right */
829 MultiByteToWideChar( CP_ACP, 0, atSubKey, -1, buff, sizeof(buff)/sizeof(WCHAR) );
830 CLSIDFromString( (LPCOLESTR)buff, &serviceProviderGUID );
831 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
833 /* The enumeration will return FALSE if we are not to continue */
834 if( !lpEnumAddressTypeCallback( &serviceProviderGUID, lpContext, 0 ) )
836 WARN("lpEnumCallback returning FALSE\n" );
837 break; /* FIXME: This most likely has to break from the procedure...*/
842 /* We only enumerate address types for 1 GUID. We've found it, so quit looking */
843 break;
846 return DP_OK;
849 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddressTypes
850 ( LPDIRECTPLAYLOBBY iface,
851 LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
852 REFGUID guidSP,
853 LPVOID lpContext,
854 DWORD dwFlags )
856 FIXME(":stub\n");
857 return DPERR_OUTOFMEMORY;
860 /********************************************************************
862 * Enumerates what applications are registered with DirectPlay by
863 * invoking the callback function with lpContext.
866 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumLocalApplications
867 ( LPDIRECTPLAYLOBBY iface,
868 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
869 LPVOID lpContext,
870 DWORD dwFlags )
872 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
874 FIXME("(%p)->(%p,%p,0x%08lx):stub\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
876 return DPERR_OUTOFMEMORY;
879 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumLocalApplications
880 ( LPDIRECTPLAYLOBBYA iface,
881 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
882 LPVOID lpContext,
883 DWORD dwFlags )
885 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
887 HKEY hkResult;
888 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Applications";
889 LPSTR guidDataSubKey = "Guid";
890 DWORD dwIndex, sizeOfSubKeyName=50;
891 char subKeyName[51];
892 FILETIME filetime;
894 TRACE("(%p)->(%p,%p,0x%08lx)\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
896 if( dwFlags != 0 )
898 return DPERR_INVALIDPARAMS;
901 if( !lpEnumLocalAppCallback || !*lpEnumLocalAppCallback )
903 return DPERR_INVALIDPARAMS;
906 /* Need to loop over the service providers in the registry */
907 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
908 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
910 /* Hmmm. Does this mean that there are no service providers? */
911 ERR(": no service providers?\n");
912 return DP_OK;
915 /* Traverse all registered applications */
916 for( dwIndex=0;
917 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
918 ++dwIndex, sizeOfSubKeyName=50 )
921 HKEY hkServiceProvider;
922 GUID serviceProviderGUID;
923 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
924 char returnBuffer[51];
925 WCHAR buff[51];
926 DPLAPPINFO dplAppInfo;
928 TRACE(" this time through: %s\n", subKeyName );
930 /* Get a handle for this particular service provider */
931 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
932 &hkServiceProvider ) != ERROR_SUCCESS )
934 ERR(": what the heck is going on?\n" );
935 continue;
938 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
939 NULL, &returnTypeGUID, returnBuffer,
940 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
942 ERR(": missing GUID registry data members\n" );
943 continue;
946 /* FIXME: Check return types to ensure we're interpreting data right */
947 MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff)/sizeof(WCHAR) );
948 CLSIDFromString( (LPCOLESTR)buff, &serviceProviderGUID );
949 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
951 dplAppInfo.dwSize = sizeof( dplAppInfo );
952 dplAppInfo.guidApplication = serviceProviderGUID;
953 dplAppInfo.u.lpszAppNameA = subKeyName;
955 EnterCriticalSection( &This->unk->DPL_lock );
957 memcpy( &This->dpl->hkCallbackKeyHack, &hkServiceProvider, sizeof( hkServiceProvider ) );
959 if( !lpEnumLocalAppCallback( &dplAppInfo, lpContext, dwFlags ) )
961 LeaveCriticalSection( &This->unk->DPL_lock );
962 break;
965 LeaveCriticalSection( &This->unk->DPL_lock );
968 return DP_OK;
971 /********************************************************************
973 * Retrieves the DPLCONNECTION structure that contains all the information
974 * needed to start and connect an application. This was generated using
975 * either the RunApplication or SetConnectionSettings methods.
977 * NOTES: If lpData is NULL then just return lpdwDataSize. This allows
978 * the data structure to be allocated by our caller which can then
979 * call this procedure/method again with a valid data pointer.
981 static HRESULT WINAPI IDirectPlayLobbyAImpl_GetConnectionSettings
982 ( LPDIRECTPLAYLOBBYA iface,
983 DWORD dwAppID,
984 LPVOID lpData,
985 LPDWORD lpdwDataSize )
987 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
988 HRESULT hr;
990 TRACE("(%p)->(0x%08lx,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
992 EnterCriticalSection( &This->unk->DPL_lock );
994 hr = DPLAYX_GetConnectionSettingsA( dwAppID,
995 lpData,
996 lpdwDataSize
999 LeaveCriticalSection( &This->unk->DPL_lock );
1001 return hr;
1004 static HRESULT WINAPI IDirectPlayLobbyWImpl_GetConnectionSettings
1005 ( LPDIRECTPLAYLOBBY iface,
1006 DWORD dwAppID,
1007 LPVOID lpData,
1008 LPDWORD lpdwDataSize )
1010 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1011 HRESULT hr;
1013 TRACE("(%p)->(0x%08lx,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
1015 EnterCriticalSection( &This->unk->DPL_lock );
1017 hr = DPLAYX_GetConnectionSettingsW( dwAppID,
1018 lpData,
1019 lpdwDataSize
1022 LeaveCriticalSection( &This->unk->DPL_lock );
1024 return hr;
1027 /********************************************************************
1029 * Retrieves the message sent between a lobby client and a DirectPlay
1030 * application. All messages are queued until received.
1033 static HRESULT WINAPI IDirectPlayLobbyAImpl_ReceiveLobbyMessage
1034 ( LPDIRECTPLAYLOBBYA iface,
1035 DWORD dwFlags,
1036 DWORD dwAppID,
1037 LPDWORD lpdwMessageFlags,
1038 LPVOID lpData,
1039 LPDWORD lpdwDataSize )
1041 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1042 FIXME(":stub %p %08lx %08lx %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1043 lpdwDataSize );
1044 return DPERR_OUTOFMEMORY;
1047 static HRESULT WINAPI IDirectPlayLobbyWImpl_ReceiveLobbyMessage
1048 ( LPDIRECTPLAYLOBBY iface,
1049 DWORD dwFlags,
1050 DWORD dwAppID,
1051 LPDWORD lpdwMessageFlags,
1052 LPVOID lpData,
1053 LPDWORD lpdwDataSize )
1055 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1056 FIXME(":stub %p %08lx %08lx %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1057 lpdwDataSize );
1058 return DPERR_OUTOFMEMORY;
1061 typedef struct tagRunApplicationEnumStruct
1063 IDirectPlayLobbyAImpl* This;
1065 GUID appGUID;
1066 LPSTR lpszPath;
1067 LPSTR lpszFileName;
1068 LPSTR lpszCommandLine;
1069 LPSTR lpszCurrentDirectory;
1070 } RunApplicationEnumStruct, *lpRunApplicationEnumStruct;
1072 /* To be called by RunApplication to find how to invoke the function */
1073 static BOOL CALLBACK RunApplicationA_EnumLocalApplications
1074 ( LPCDPLAPPINFO lpAppInfo,
1075 LPVOID lpContext,
1076 DWORD dwFlags )
1078 lpRunApplicationEnumStruct lpData = (lpRunApplicationEnumStruct)lpContext;
1080 if( IsEqualGUID( &lpAppInfo->guidApplication, &lpData->appGUID ) )
1082 char returnBuffer[200];
1083 DWORD returnType, sizeOfReturnBuffer;
1084 LPSTR clSubKey = "CommandLine";
1085 LPSTR cdSubKey = "CurrentDirectory";
1086 LPSTR fileSubKey = "File";
1087 LPSTR pathSubKey = "Path";
1089 /* FIXME: Lazy man hack - dplay struct has the present reg key saved */
1091 sizeOfReturnBuffer = 200;
1093 /* Get all the appropriate data from the registry */
1094 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, clSubKey,
1095 NULL, &returnType, returnBuffer,
1096 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1098 ERR( ": missing CommandLine registry data member\n" );
1100 else
1102 if ((lpData->lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1103 strcpy( lpData->lpszCommandLine, returnBuffer );
1106 sizeOfReturnBuffer = 200;
1108 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, cdSubKey,
1109 NULL, &returnType, returnBuffer,
1110 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1112 ERR( ": missing CurrentDirectory registry data member\n" );
1114 else
1116 if ((lpData->lpszCurrentDirectory = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1117 strcpy( lpData->lpszCurrentDirectory, returnBuffer );
1120 sizeOfReturnBuffer = 200;
1122 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, fileSubKey,
1123 NULL, &returnType, returnBuffer,
1124 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1126 ERR( ": missing File registry data member\n" );
1128 else
1130 if ((lpData->lpszFileName = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1131 strcpy( lpData->lpszFileName, returnBuffer );
1134 sizeOfReturnBuffer = 200;
1136 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, pathSubKey,
1137 NULL, &returnType, returnBuffer,
1138 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1140 ERR( ": missing Path registry data member\n" );
1142 else
1144 if ((lpData->lpszPath = HeapAlloc( GetProcessHeap(), 0, strlen(returnBuffer)+1 )))
1145 strcpy( lpData->lpszPath, returnBuffer );
1148 return FALSE; /* No need to keep going as we found what we wanted */
1151 return TRUE; /* Keep enumerating, haven't found the application yet */
1154 BOOL DPL_CreateAndSetLobbyHandles( DWORD dwDestProcessId, HANDLE hDestProcess,
1155 LPHANDLE lphStart, LPHANDLE lphDeath,
1156 LPHANDLE lphRead )
1158 /* These are the handles for the created process */
1159 HANDLE hAppStart, hAppDeath, hAppRead, hTemp;
1160 SECURITY_ATTRIBUTES s_attrib;
1162 s_attrib.nLength = sizeof( s_attrib );
1163 s_attrib.lpSecurityDescriptor = NULL;
1164 s_attrib.bInheritHandle = TRUE;
1166 /* FIXME: Is there a handle leak here? */
1167 hTemp = CreateEventA( &s_attrib, TRUE, FALSE, NULL );
1168 *lphStart = ConvertToGlobalHandle( hTemp );
1170 hTemp = CreateEventA( &s_attrib, TRUE, FALSE, NULL );
1171 *lphDeath = ConvertToGlobalHandle( hTemp );
1173 hTemp = CreateEventA( &s_attrib, TRUE, FALSE, NULL );
1174 *lphRead = ConvertToGlobalHandle( hTemp );
1176 if( ( !DuplicateHandle( GetCurrentProcess(), *lphStart,
1177 hDestProcess, &hAppStart,
1178 0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1179 ( !DuplicateHandle( GetCurrentProcess(), *lphDeath,
1180 hDestProcess, &hAppDeath,
1181 0, FALSE, DUPLICATE_SAME_ACCESS ) ) ||
1182 ( !DuplicateHandle( GetCurrentProcess(), *lphRead,
1183 hDestProcess, &hAppRead,
1184 0, FALSE, DUPLICATE_SAME_ACCESS ) )
1187 /* FIXME: Handle leak... */
1188 ERR( "Unable to dup handles\n" );
1189 return FALSE;
1192 if( !DPLAYX_SetLobbyHandles( dwDestProcessId,
1193 hAppStart, hAppDeath, hAppRead ) )
1195 return FALSE;
1198 return TRUE;
1202 /********************************************************************
1204 * Starts an application and passes to it all the information to
1205 * connect to a session.
1208 static HRESULT WINAPI IDirectPlayLobbyAImpl_RunApplication
1209 ( LPDIRECTPLAYLOBBYA iface,
1210 DWORD dwFlags,
1211 LPDWORD lpdwAppID,
1212 LPDPLCONNECTION lpConn,
1213 HANDLE hReceiveEvent )
1215 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1216 HRESULT hr;
1217 RunApplicationEnumStruct enumData;
1218 char temp[200];
1219 STARTUPINFOA startupInfo;
1220 PROCESS_INFORMATION newProcessInfo;
1221 LPSTR appName;
1222 DWORD dwSuspendCount;
1223 HANDLE hStart, hDeath, hSettingRead;
1225 TRACE( "(%p)->(0x%08lx,%p,%p,%p)\n",
1226 This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1228 if( dwFlags != 0 )
1230 return DPERR_INVALIDPARAMS;
1233 if( DPLAYX_AnyLobbiesWaitingForConnSettings() )
1235 FIXME( "Waiting lobby not being handled correctly\n" );
1238 EnterCriticalSection( &This->unk->DPL_lock );
1240 ZeroMemory( &enumData, sizeof( enumData ) );
1241 enumData.This = This;
1242 enumData.appGUID = lpConn->lpSessionDesc->guidApplication;
1244 /* Our callback function will fill up the enumData structure with all the information
1245 required to start a new process */
1246 IDirectPlayLobby_EnumLocalApplications( iface, RunApplicationA_EnumLocalApplications,
1247 (LPVOID)(&enumData), 0 );
1249 /* First the application name */
1250 strcpy( temp, enumData.lpszPath );
1251 strcat( temp, "\\" );
1252 strcat( temp, enumData.lpszFileName );
1253 HeapFree( GetProcessHeap(), 0, enumData.lpszPath );
1254 HeapFree( GetProcessHeap(), 0, enumData.lpszFileName );
1255 if ((appName = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 ))) strcpy( appName, temp );
1257 /* Now the command line */
1258 strcat( temp, " " );
1259 strcat( temp, enumData.lpszCommandLine );
1260 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1261 if ((enumData.lpszCommandLine = HeapAlloc( GetProcessHeap(), 0, strlen(temp)+1 )))
1262 strcpy( enumData.lpszCommandLine, temp );
1264 ZeroMemory( &startupInfo, sizeof( startupInfo ) );
1265 startupInfo.cb = sizeof( startupInfo );
1266 /* FIXME: Should any fields be filled in? */
1268 ZeroMemory( &newProcessInfo, sizeof( newProcessInfo ) );
1270 if( !CreateProcessA( appName,
1271 enumData.lpszCommandLine,
1272 NULL,
1273 NULL,
1274 FALSE,
1275 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE | CREATE_SUSPENDED, /* Creation Flags */
1276 NULL,
1277 enumData.lpszCurrentDirectory,
1278 &startupInfo,
1279 &newProcessInfo
1283 ERR( "Failed to create process for app %s\n", appName );
1285 HeapFree( GetProcessHeap(), 0, appName );
1286 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1287 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1289 LeaveCriticalSection( &This->unk->DPL_lock );
1290 return DPERR_CANTCREATEPROCESS;
1293 HeapFree( GetProcessHeap(), 0, appName );
1294 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1295 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1297 /* Reserve this global application id! */
1298 if( !DPLAYX_CreateLobbyApplication( newProcessInfo.dwProcessId ) )
1300 ERR( "Unable to create global application data for 0x%08lx\n",
1301 newProcessInfo.dwProcessId );
1304 hr = IDirectPlayLobby_SetConnectionSettings( iface, 0, newProcessInfo.dwProcessId, lpConn );
1306 if( hr != DP_OK )
1308 ERR( "SetConnectionSettings failure %s\n", DPLAYX_HresultToString( hr ) );
1309 LeaveCriticalSection( &This->unk->DPL_lock );
1310 return hr;
1313 /* Setup the handles for application notification */
1314 DPL_CreateAndSetLobbyHandles( newProcessInfo.dwProcessId,
1315 newProcessInfo.hProcess,
1316 &hStart, &hDeath, &hSettingRead );
1318 /* Setup the message thread ID */
1319 This->dpl->dwMsgThread =
1320 CreateLobbyMessageReceptionThread( hReceiveEvent, hStart, hDeath, hSettingRead );
1322 DPLAYX_SetLobbyMsgThreadId( newProcessInfo.dwProcessId, This->dpl->dwMsgThread );
1324 LeaveCriticalSection( &This->unk->DPL_lock );
1326 /* Everything seems to have been set correctly, update the dwAppID */
1327 *lpdwAppID = newProcessInfo.dwProcessId;
1329 /* Unsuspend the process - should return the prev suspension count */
1330 if( ( dwSuspendCount = ResumeThread( newProcessInfo.hThread ) ) != 1 )
1332 ERR( "ResumeThread failed with 0x%08lx\n", dwSuspendCount );
1335 return DP_OK;
1338 static HRESULT WINAPI IDirectPlayLobbyWImpl_RunApplication
1339 ( LPDIRECTPLAYLOBBY iface,
1340 DWORD dwFlags,
1341 LPDWORD lpdwAppID,
1342 LPDPLCONNECTION lpConn,
1343 HANDLE hReceiveEvent )
1345 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1346 FIXME( "(%p)->(0x%08lx,%p,%p,%p):stub\n", This, dwFlags, lpdwAppID, lpConn, (void *)hReceiveEvent );
1347 return DPERR_OUTOFMEMORY;
1350 /********************************************************************
1352 * Sends a message between the application and the lobby client.
1353 * All messages are queued until received.
1356 static HRESULT WINAPI IDirectPlayLobbyAImpl_SendLobbyMessage
1357 ( LPDIRECTPLAYLOBBYA iface,
1358 DWORD dwFlags,
1359 DWORD dwAppID,
1360 LPVOID lpData,
1361 DWORD dwDataSize )
1363 FIXME(":stub\n");
1364 return DPERR_OUTOFMEMORY;
1367 static HRESULT WINAPI IDirectPlayLobbyWImpl_SendLobbyMessage
1368 ( LPDIRECTPLAYLOBBY iface,
1369 DWORD dwFlags,
1370 DWORD dwAppID,
1371 LPVOID lpData,
1372 DWORD dwDataSize )
1374 FIXME(":stub\n");
1375 return DPERR_OUTOFMEMORY;
1378 /********************************************************************
1380 * Modifies the DPLCONNECTION structure to contain all information
1381 * needed to start and connect an application.
1384 static HRESULT WINAPI IDirectPlayLobbyWImpl_SetConnectionSettings
1385 ( LPDIRECTPLAYLOBBY iface,
1386 DWORD dwFlags,
1387 DWORD dwAppID,
1388 LPDPLCONNECTION lpConn )
1390 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1391 HRESULT hr;
1393 TRACE("(%p)->(0x%08lx,0x%08lx,%p)\n", This, dwFlags, dwAppID, lpConn );
1395 EnterCriticalSection( &This->unk->DPL_lock );
1397 hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1399 /* FIXME: Don't think that this is supposed to fail, but the docuementation
1400 is somewhat sketchy. I'll try creating a lobby application
1401 for this... */
1402 if( hr == DPERR_NOTLOBBIED )
1404 FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
1405 if( dwAppID == 0 )
1407 dwAppID = GetCurrentProcessId();
1409 DPLAYX_CreateLobbyApplication( dwAppID );
1410 hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1413 LeaveCriticalSection( &This->unk->DPL_lock );
1415 return hr;
1418 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetConnectionSettings
1419 ( LPDIRECTPLAYLOBBYA iface,
1420 DWORD dwFlags,
1421 DWORD dwAppID,
1422 LPDPLCONNECTION lpConn )
1424 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1425 HRESULT hr;
1427 TRACE("(%p)->(0x%08lx,0x%08lx,%p)\n", This, dwFlags, dwAppID, lpConn );
1429 EnterCriticalSection( &This->unk->DPL_lock );
1431 hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1433 /* FIXME: Don't think that this is supposed to fail, but the docuementation
1434 is somewhat sketchy. I'll try creating a lobby application
1435 for this... */
1436 if( hr == DPERR_NOTLOBBIED )
1438 FIXME( "Unlobbied app setting connections. Is this correct behavior?\n" );
1439 dwAppID = GetCurrentProcessId();
1440 DPLAYX_CreateLobbyApplication( dwAppID );
1441 hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1444 LeaveCriticalSection( &This->unk->DPL_lock );
1446 return hr;
1449 /********************************************************************
1451 * Registers an event that will be set when a lobby message is received.
1454 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetLobbyMessageEvent
1455 ( LPDIRECTPLAYLOBBYA iface,
1456 DWORD dwFlags,
1457 DWORD dwAppID,
1458 HANDLE hReceiveEvent )
1460 FIXME(":stub\n");
1461 return DPERR_OUTOFMEMORY;
1464 static HRESULT WINAPI IDirectPlayLobbyWImpl_SetLobbyMessageEvent
1465 ( LPDIRECTPLAYLOBBY iface,
1466 DWORD dwFlags,
1467 DWORD dwAppID,
1468 HANDLE hReceiveEvent )
1470 FIXME(":stub\n");
1471 return DPERR_OUTOFMEMORY;
1475 /* DPL 2 methods */
1476 static HRESULT WINAPI IDirectPlayLobby2WImpl_CreateCompoundAddress
1477 ( LPDIRECTPLAYLOBBY2 iface,
1478 LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1479 DWORD dwElementCount,
1480 LPVOID lpAddress,
1481 LPDWORD lpdwAddressSize )
1483 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, FALSE );
1486 static HRESULT WINAPI IDirectPlayLobby2AImpl_CreateCompoundAddress
1487 ( LPDIRECTPLAYLOBBY2A iface,
1488 LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1489 DWORD dwElementCount,
1490 LPVOID lpAddress,
1491 LPDWORD lpdwAddressSize )
1493 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, TRUE );
1496 HRESULT DPL_CreateCompoundAddress
1497 ( LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1498 DWORD dwElementCount,
1499 LPVOID lpAddress,
1500 LPDWORD lpdwAddressSize,
1501 BOOL bAnsiInterface )
1503 DWORD dwSizeRequired = 0;
1504 DWORD dwElements;
1505 LPCDPCOMPOUNDADDRESSELEMENT lpOrigElements = lpElements;
1507 TRACE("(%p,0x%08lx,%p,%p)\n", lpElements, dwElementCount, lpAddress, lpdwAddressSize );
1509 /* Parameter check */
1510 if( ( lpElements == NULL ) ||
1511 ( dwElementCount == 0 ) /* FIXME: Not sure if this is a failure case */
1514 return DPERR_INVALIDPARAMS;
1517 /* Add the total size chunk */
1518 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DWORD );
1520 /* Calculate the size of the buffer required */
1521 for ( dwElements = dwElementCount; dwElements > 0; --dwElements, ++lpElements )
1523 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1524 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1527 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( GUID );
1529 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1530 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1531 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1534 if( !bAnsiInterface )
1536 ERR( "Ansi GUIDs used for unicode interface\n" );
1537 return DPERR_INVALIDFLAGS;
1540 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize;
1542 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1543 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1544 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1547 if( bAnsiInterface )
1549 ERR( "Unicode GUIDs used for ansi interface\n" );
1550 return DPERR_INVALIDFLAGS;
1553 FIXME( "Right size for unicode interface?\n" );
1554 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize * sizeof( WCHAR );
1556 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1558 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( WORD );
1560 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1562 FIXME( "Right size for unicode interface?\n" );
1563 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DPCOMPORTADDRESS ); /* FIXME: Right size? */
1565 else
1567 ERR( "Unknown GUID %s\n", debugstr_guid(&lpElements->guidDataType) );
1568 return DPERR_INVALIDFLAGS;
1572 /* The user wants to know how big a buffer to allocate for us */
1573 if( ( lpAddress == NULL ) ||
1574 ( *lpdwAddressSize < dwSizeRequired )
1577 *lpdwAddressSize = dwSizeRequired;
1578 return DPERR_BUFFERTOOSMALL;
1581 /* Add the total size chunk */
1583 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1585 CopyMemory( &lpdpAddress->guidDataType, &DPAID_TotalSize, sizeof( GUID ) );
1586 lpdpAddress->dwDataSize = sizeof( DWORD );
1587 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1589 *(LPDWORD)lpAddress = dwSizeRequired;
1590 lpAddress = (char *) lpAddress + sizeof( DWORD );
1593 /* Calculate the size of the buffer required */
1594 for( dwElements = dwElementCount, lpElements = lpOrigElements;
1595 dwElements > 0;
1596 --dwElements, ++lpElements )
1598 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1599 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1602 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1604 CopyMemory( &lpdpAddress->guidDataType, &lpElements->guidDataType,
1605 sizeof( GUID ) );
1606 lpdpAddress->dwDataSize = sizeof( GUID );
1607 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1609 CopyMemory( lpAddress, lpElements->lpData, sizeof( GUID ) );
1610 lpAddress = (char *) lpAddress + sizeof( GUID );
1612 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1613 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1614 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1617 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1619 CopyMemory( &lpdpAddress->guidDataType, &lpElements->guidDataType,
1620 sizeof( GUID ) );
1621 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1622 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1624 lstrcpynA( (LPSTR)lpAddress,
1625 (LPCSTR)lpElements->lpData,
1626 lpElements->dwDataSize );
1627 lpAddress = (char *) lpAddress + lpElements->dwDataSize;
1629 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1630 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1631 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1634 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1636 CopyMemory( &lpdpAddress->guidDataType, &lpElements->guidDataType,
1637 sizeof( GUID ) );
1638 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1639 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1641 lstrcpynW( (LPWSTR)lpAddress,
1642 (LPCWSTR)lpElements->lpData,
1643 lpElements->dwDataSize );
1644 lpAddress = (char *) lpAddress + lpElements->dwDataSize * sizeof( WCHAR );
1646 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1648 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1650 CopyMemory( &lpdpAddress->guidDataType, &lpElements->guidDataType,
1651 sizeof( GUID ) );
1652 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1653 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1655 *((LPWORD)lpAddress) = *((LPWORD)lpElements->lpData);
1656 lpAddress = (char *) lpAddress + sizeof( WORD );
1658 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1660 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1662 CopyMemory( &lpdpAddress->guidDataType, &lpElements->guidDataType,
1663 sizeof( GUID ) );
1664 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1665 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1667 CopyMemory( lpAddress, lpElements->lpData, sizeof( DPADDRESS ) );
1668 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1672 return DP_OK;
1675 /* DPL 3 methods */
1677 static HRESULT WINAPI IDirectPlayLobby3WImpl_ConnectEx
1678 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFIID riid,
1679 LPVOID* lplpDP, IUnknown* pUnk )
1681 ICOM_THIS( IDirectPlayLobbyAImpl, iface );
1682 return DPL_ConnectEx( This, dwFlags, riid, lplpDP, pUnk );
1685 static HRESULT WINAPI IDirectPlayLobby3AImpl_ConnectEx
1686 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, REFIID riid,
1687 LPVOID* lplpDP, IUnknown* pUnk )
1689 ICOM_THIS( IDirectPlayLobbyAImpl, iface );
1690 return DPL_ConnectEx( This, dwFlags, riid, lplpDP, pUnk );
1693 static HRESULT WINAPI IDirectPlayLobby3WImpl_RegisterApplication
1694 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
1696 FIXME(":stub\n");
1697 return DP_OK;
1700 static HRESULT WINAPI IDirectPlayLobby3AImpl_RegisterApplication
1701 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
1703 FIXME(":stub\n");
1704 return DP_OK;
1707 static HRESULT WINAPI IDirectPlayLobby3WImpl_UnregisterApplication
1708 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFGUID lpAppDesc )
1710 FIXME(":stub\n");
1711 return DP_OK;
1714 static HRESULT WINAPI IDirectPlayLobby3AImpl_UnregisterApplication
1715 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, REFGUID lpAppDesc )
1717 FIXME(":stub\n");
1718 return DP_OK;
1721 static HRESULT WINAPI IDirectPlayLobby3WImpl_WaitForConnectionSettings
1722 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags )
1724 HRESULT hr = DP_OK;
1725 BOOL bStartWait = (dwFlags & DPLWAIT_CANCEL) ? FALSE : TRUE;
1727 TRACE( "(%p)->(0x%08lx)\n", iface, dwFlags );
1729 if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
1731 /* FIXME: What is the correct error return code? */
1732 hr = DPERR_NOTLOBBIED;
1735 return hr;
1738 static HRESULT WINAPI IDirectPlayLobby3AImpl_WaitForConnectionSettings
1739 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags )
1741 HRESULT hr = DP_OK;
1742 BOOL bStartWait = (dwFlags & DPLWAIT_CANCEL) ? FALSE : TRUE;
1744 TRACE( "(%p)->(0x%08lx)\n", iface, dwFlags );
1746 if( DPLAYX_WaitForConnectionSettings( bStartWait ) )
1748 /* FIXME: What is the correct error return code? */
1749 hr = DPERR_NOTLOBBIED;
1752 return hr;
1756 /* Virtual Table definitions for DPL{1,2,3}{A,W} */
1758 /* Note: Hack so we can reuse the old functions without compiler warnings */
1759 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1760 # define XCAST(fun) (typeof(directPlayLobbyAVT.fun))
1761 #else
1762 # define XCAST(fun) (void*)
1763 #endif
1765 /* Direct Play Lobby 1 (ascii) Virtual Table for methods */
1766 /* All lobby 1 methods are exactly the same except QueryInterface */
1767 static struct ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyAVT =
1769 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1771 XCAST(QueryInterface)DPL_QueryInterface,
1772 XCAST(AddRef)DPL_AddRef,
1773 XCAST(Release)DPL_Release,
1775 IDirectPlayLobbyAImpl_Connect,
1776 IDirectPlayLobbyAImpl_CreateAddress,
1777 IDirectPlayLobbyAImpl_EnumAddress,
1778 IDirectPlayLobbyAImpl_EnumAddressTypes,
1779 IDirectPlayLobbyAImpl_EnumLocalApplications,
1780 IDirectPlayLobbyAImpl_GetConnectionSettings,
1781 IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1782 IDirectPlayLobbyAImpl_RunApplication,
1783 IDirectPlayLobbyAImpl_SendLobbyMessage,
1784 IDirectPlayLobbyAImpl_SetConnectionSettings,
1785 IDirectPlayLobbyAImpl_SetLobbyMessageEvent
1787 #undef XCAST
1790 /* Note: Hack so we can reuse the old functions without compiler warnings */
1791 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1792 # define XCAST(fun) (typeof(directPlayLobbyWVT.fun))
1793 #else
1794 # define XCAST(fun) (void*)
1795 #endif
1797 /* Direct Play Lobby 1 (unicode) Virtual Table for methods */
1798 static ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyWVT =
1800 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1802 XCAST(QueryInterface)DPL_QueryInterface,
1803 XCAST(AddRef)DPL_AddRef,
1804 XCAST(Release)DPL_Release,
1806 IDirectPlayLobbyWImpl_Connect,
1807 IDirectPlayLobbyWImpl_CreateAddress,
1808 IDirectPlayLobbyWImpl_EnumAddress,
1809 IDirectPlayLobbyWImpl_EnumAddressTypes,
1810 IDirectPlayLobbyWImpl_EnumLocalApplications,
1811 IDirectPlayLobbyWImpl_GetConnectionSettings,
1812 IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1813 IDirectPlayLobbyWImpl_RunApplication,
1814 IDirectPlayLobbyWImpl_SendLobbyMessage,
1815 IDirectPlayLobbyWImpl_SetConnectionSettings,
1816 IDirectPlayLobbyWImpl_SetLobbyMessageEvent
1818 #undef XCAST
1820 /* Note: Hack so we can reuse the old functions without compiler warnings */
1821 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1822 # define XCAST(fun) (typeof(directPlayLobby2AVT.fun))
1823 #else
1824 # define XCAST(fun) (void*)
1825 #endif
1827 /* Direct Play Lobby 2 (ascii) Virtual Table for methods */
1828 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2AVT =
1830 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1832 XCAST(QueryInterface)DPL_QueryInterface,
1833 XCAST(AddRef)DPL_AddRef,
1834 XCAST(Release)DPL_Release,
1836 XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
1837 XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
1838 XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
1839 XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
1840 XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
1841 XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
1842 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1843 XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
1844 XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
1845 XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
1846 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,
1848 IDirectPlayLobby2AImpl_CreateCompoundAddress
1850 #undef XCAST
1852 /* Note: Hack so we can reuse the old functions without compiler warnings */
1853 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1854 # define XCAST(fun) (typeof(directPlayLobby2AVT.fun))
1855 #else
1856 # define XCAST(fun) (void*)
1857 #endif
1859 /* Direct Play Lobby 2 (unicode) Virtual Table for methods */
1860 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2WVT =
1862 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1864 XCAST(QueryInterface)DPL_QueryInterface,
1865 XCAST(AddRef)DPL_AddRef,
1866 XCAST(Release)DPL_Release,
1868 XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
1869 XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
1870 XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
1871 XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
1872 XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
1873 XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
1874 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1875 XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
1876 XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
1877 XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
1878 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,
1880 IDirectPlayLobby2WImpl_CreateCompoundAddress
1882 #undef XCAST
1884 /* Direct Play Lobby 3 (ascii) Virtual Table for methods */
1886 /* Note: Hack so we can reuse the old functions without compiler warnings */
1887 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1888 # define XCAST(fun) (typeof(directPlayLobby3AVT.fun))
1889 #else
1890 # define XCAST(fun) (void*)
1891 #endif
1893 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3AVT =
1895 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1896 XCAST(QueryInterface)DPL_QueryInterface,
1897 XCAST(AddRef)DPL_AddRef,
1898 XCAST(Release)DPL_Release,
1900 XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
1901 XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
1902 XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
1903 XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
1904 XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
1905 XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
1906 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1907 XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
1908 XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
1909 XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
1910 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,
1912 XCAST(CreateCompoundAddress)IDirectPlayLobby2AImpl_CreateCompoundAddress,
1914 IDirectPlayLobby3AImpl_ConnectEx,
1915 IDirectPlayLobby3AImpl_RegisterApplication,
1916 IDirectPlayLobby3AImpl_UnregisterApplication,
1917 IDirectPlayLobby3AImpl_WaitForConnectionSettings
1919 #undef XCAST
1921 /* Direct Play Lobby 3 (unicode) Virtual Table for methods */
1923 /* Note: Hack so we can reuse the old functions without compiler warnings */
1924 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1925 # define XCAST(fun) (typeof(directPlayLobby3WVT.fun))
1926 #else
1927 # define XCAST(fun) (void*)
1928 #endif
1930 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3WVT =
1932 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1933 XCAST(QueryInterface)DPL_QueryInterface,
1934 XCAST(AddRef)DPL_AddRef,
1935 XCAST(Release)DPL_Release,
1937 XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
1938 XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
1939 XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
1940 XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
1941 XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
1942 XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
1943 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1944 XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
1945 XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
1946 XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
1947 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,
1949 XCAST(CreateCompoundAddress)IDirectPlayLobby2WImpl_CreateCompoundAddress,
1951 IDirectPlayLobby3WImpl_ConnectEx,
1952 IDirectPlayLobby3WImpl_RegisterApplication,
1953 IDirectPlayLobby3WImpl_UnregisterApplication,
1954 IDirectPlayLobby3WImpl_WaitForConnectionSettings
1956 #undef XCAST
1959 /*********************************************************
1961 * Direct Play Lobby Interface Implementation
1963 *********************************************************/
1965 /***************************************************************************
1966 * DirectPlayLobbyCreateA (DPLAYX.4)
1969 HRESULT WINAPI DirectPlayLobbyCreateA( LPGUID lpGUIDDSP,
1970 LPDIRECTPLAYLOBBYA *lplpDPL,
1971 IUnknown *lpUnk,
1972 LPVOID lpData,
1973 DWORD dwDataSize )
1975 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08lx\n",
1976 lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);
1978 /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
1979 * equal 0. These fields are mostly for future expansion.
1981 if ( lpGUIDDSP || lpData || dwDataSize )
1983 *lplpDPL = NULL;
1984 return DPERR_INVALIDPARAMS;
1987 if( lpUnk )
1989 *lplpDPL = NULL;
1990 ERR("Bad parameters!\n" );
1991 return CLASS_E_NOAGGREGATION;
1994 return DPL_CreateInterface( &IID_IDirectPlayLobbyA, (void**)lplpDPL );
1997 /***************************************************************************
1998 * DirectPlayLobbyCreateW (DPLAYX.5)
2001 HRESULT WINAPI DirectPlayLobbyCreateW( LPGUID lpGUIDDSP,
2002 LPDIRECTPLAYLOBBY *lplpDPL,
2003 IUnknown *lpUnk,
2004 LPVOID lpData,
2005 DWORD dwDataSize )
2007 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08lx\n",
2008 lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);
2010 /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
2011 * equal 0. These fields are mostly for future expansion.
2013 if ( lpGUIDDSP || lpData || dwDataSize )
2015 *lplpDPL = NULL;
2016 ERR("Bad parameters!\n" );
2017 return DPERR_INVALIDPARAMS;
2020 if( lpUnk )
2022 *lplpDPL = NULL;
2023 ERR("Bad parameters!\n" );
2024 return CLASS_E_NOAGGREGATION;
2027 return DPL_CreateInterface( &IID_IDirectPlayLobby, (void**)lplpDPL );