1 /* Direct Play Lobby 2 & 3 Implementation
3 * Copyright 1998,1999,2000 - Peter Hunnisett
5 * <presently under construction - contact hunnise@nortelnetworks.com>
14 #include "debugtools.h"
18 #include "dplayx_global.h"
20 DEFAULT_DEBUG_CHANNEL(dplay)
23 /* Forward declarations for this module helper methods */
24 HRESULT DPL_CreateCompoundAddress ( LPCDPCOMPOUNDADDRESSELEMENT lpElements, DWORD dwElementCount,
25 LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface );
27 HRESULT DPL_CreateAddress( REFGUID guidSP, REFGUID guidDataType, LPCVOID lpData, DWORD dwDataSize,
28 LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface );
32 static HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
33 DWORD dwAddressSize, LPVOID lpContext );
36 /*****************************************************************************
37 * Predeclare the interface implementation structures
39 typedef struct IDirectPlayLobbyImpl IDirectPlayLobbyAImpl;
40 typedef struct IDirectPlayLobbyImpl IDirectPlayLobbyWImpl;
41 typedef struct IDirectPlayLobby2Impl IDirectPlayLobby2AImpl;
42 typedef struct IDirectPlayLobby2Impl IDirectPlayLobby2WImpl;
43 typedef struct IDirectPlayLobby3Impl IDirectPlayLobby3AImpl;
44 typedef struct IDirectPlayLobby3Impl IDirectPlayLobby3WImpl;
46 /*****************************************************************************
47 * IDirectPlayLobby {1,2,3} implementation structure
49 * The philosophy behind this extra pointer derefernce is that I wanted to
50 * have the same structure for all types of objects without having to do
51 * alot of casting. I also only wanted to implement an interface in the
52 * object it was "released" with IUnknown interface being implemented in the 1 version.
53 * Of course, with these new interfaces comes the data required to keep the state required
54 * by these interfaces. So, basically, the pointers contain the data associated with
55 * a release. If you use the data associated with release 3 in a release 2 object, you'll
56 * get a run time trap, as that won't have any data.
60 typedef struct tagDirectPlayLobbyIUnknownData
63 CRITICAL_SECTION DPL_lock;
64 } DirectPlayLobbyIUnknownData;
66 typedef struct tagDirectPlayLobbyData
68 HKEY hkCallbackKeyHack;
69 } DirectPlayLobbyData;
71 typedef struct tagDirectPlayLobby2Data
74 } DirectPlayLobby2Data;
76 typedef struct tagDirectPlayLobby3Data
79 } DirectPlayLobby3Data;
81 #define DPL_IMPL_FIELDS \
82 DirectPlayLobbyIUnknownData* unk; \
83 DirectPlayLobbyData* dpl; \
84 DirectPlayLobby2Data* dpl2; \
85 DirectPlayLobby3Data* dpl3;
87 struct IDirectPlayLobbyImpl
89 ICOM_VFIELD(IDirectPlayLobby);
93 struct IDirectPlayLobby2Impl
95 ICOM_VFIELD(IDirectPlayLobby2);
99 struct IDirectPlayLobby3Impl
101 ICOM_VFIELD(IDirectPlayLobby3);
106 /* Forward declarations of virtual tables */
107 static ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyWVT;
108 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2WVT;
109 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3WVT;
111 static ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyAVT;
112 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2AVT;
113 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3AVT;
118 /* The COM interface for upversioning an interface
119 * We've been given a GUID (riid) and we need to replace the present
120 * interface with that of the requested interface.
122 * Snip from some Microsoft document:
123 * There are four requirements for implementations of QueryInterface (In these
124 * cases, "must succeed" means "must succeed barring catastrophic failure."):
126 * * The set of interfaces accessible on an object through
127 * IUnknown::QueryInterface must be static, not dynamic. This means that
128 * if a call to QueryInterface for a pointer to a specified interface
129 * succeeds the first time, it must succeed again, and if it fails the
130 * first time, it must fail on all subsequent queries.
131 * * It must be symmetric ~W if a client holds a pointer to an interface on
132 * an object, and queries for that interface, the call must succeed.
133 * * It must be reflexive ~W if a client holding a pointer to one interface
134 * queries successfully for another, a query through the obtained pointer
135 * for the first interface must succeed.
136 * * It must be transitive ~W if a client holding a pointer to one interface
137 * queries successfully for a second, and through that pointer queries
138 * successfully for a third interface, a query for the first interface
139 * through the pointer for the third interface must succeed.
141 * As you can see, this interface doesn't qualify but will most likely
142 * be good enough for the time being.
146 BOOL DPL_CreateIUnknown( LPVOID lpDPL )
148 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
150 This->unk = (DirectPlayLobbyIUnknownData*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
151 sizeof( *(This->unk) ) );
152 if ( This->unk == NULL )
157 InitializeCriticalSection( &This->unk->DPL_lock );
159 IDirectPlayLobby_AddRef( (LPDIRECTPLAYLOBBYA)lpDPL );
164 BOOL DPL_DestroyIUnknown( LPVOID lpDPL )
166 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
168 DeleteCriticalSection( &This->unk->DPL_lock );
169 HeapFree( GetProcessHeap(), 0, This->unk );
174 BOOL DPL_CreateLobby1( LPVOID lpDPL )
176 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
178 This->dpl = (DirectPlayLobbyData*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
179 sizeof( *(This->dpl) ) );
180 if ( This->dpl == NULL )
188 BOOL DPL_DestroyLobby1( LPVOID lpDPL )
190 ICOM_THIS(IDirectPlayLobbyAImpl,lpDPL);
192 /* Delete the contents */
193 HeapFree( GetProcessHeap(), 0, This->dpl );
198 BOOL DPL_CreateLobby2( LPVOID lpDPL )
200 ICOM_THIS(IDirectPlayLobby2AImpl,lpDPL);
202 This->dpl2 = (DirectPlayLobby2Data*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
203 sizeof( *(This->dpl2) ) );
204 if ( This->dpl2 == NULL )
212 BOOL DPL_DestroyLobby2( LPVOID lpDPL )
214 ICOM_THIS(IDirectPlayLobby2AImpl,lpDPL);
216 HeapFree( GetProcessHeap(), 0, This->dpl2 );
221 BOOL DPL_CreateLobby3( LPVOID lpDPL )
223 ICOM_THIS(IDirectPlayLobby3AImpl,lpDPL);
225 This->dpl3 = (DirectPlayLobby3Data*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
226 sizeof( *(This->dpl3) ) );
227 if ( This->dpl3 == NULL )
235 BOOL DPL_DestroyLobby3( LPVOID lpDPL )
237 ICOM_THIS(IDirectPlayLobby3AImpl,lpDPL);
239 HeapFree( GetProcessHeap(), 0, This->dpl3 );
245 /* Helper function for DirectPlayLobby QueryInterface */
247 HRESULT directPlayLobby_QueryInterface
248 ( REFIID riid, LPVOID* ppvObj )
250 if( IsEqualGUID( &IID_IDirectPlayLobby, riid ) )
252 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
253 sizeof( IDirectPlayLobbyWImpl ) );
255 if( *ppvObj == NULL )
257 return E_OUTOFMEMORY;
260 /* new scope for variable declaration */
262 ICOM_THIS(IDirectPlayLobbyWImpl,*ppvObj);
264 ICOM_VTBL(This) = &directPlayLobbyWVT;
266 if ( DPL_CreateIUnknown( (LPVOID)This ) &&
267 DPL_CreateLobby1( (LPVOID)This )
277 else if( IsEqualGUID( &IID_IDirectPlayLobbyA, riid ) )
279 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
280 sizeof( IDirectPlayLobbyAImpl ) );
282 if( *ppvObj == NULL )
284 return E_OUTOFMEMORY;
288 ICOM_THIS(IDirectPlayLobbyAImpl,*ppvObj);
290 ICOM_VTBL(This) = &directPlayLobbyAVT;
292 if ( DPL_CreateIUnknown( (LPVOID)This ) &&
293 DPL_CreateLobby1( (LPVOID)This )
302 else if( IsEqualGUID( &IID_IDirectPlayLobby2, riid ) )
304 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
305 sizeof( IDirectPlayLobby2WImpl ) );
307 if( *ppvObj == NULL )
309 return E_OUTOFMEMORY;
313 ICOM_THIS(IDirectPlayLobby2WImpl,*ppvObj);
315 ICOM_VTBL(This) = &directPlayLobby2WVT;
317 if ( DPL_CreateIUnknown( (LPVOID)This ) &&
318 DPL_CreateLobby1( (LPVOID)This ) &&
319 DPL_CreateLobby2( (LPVOID)This )
328 else if( IsEqualGUID( &IID_IDirectPlayLobby2A, riid ) )
330 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
331 sizeof( IDirectPlayLobby2AImpl ) );
333 if( *ppvObj == NULL )
335 return E_OUTOFMEMORY;
339 ICOM_THIS(IDirectPlayLobby2AImpl,*ppvObj);
341 ICOM_VTBL(This) = &directPlayLobby2AVT;
343 if ( DPL_CreateIUnknown( (LPVOID)This ) &&
344 DPL_CreateLobby1( (LPVOID)This ) &&
345 DPL_CreateLobby2( (LPVOID)This )
354 else if( IsEqualGUID( &IID_IDirectPlayLobby3, riid ) )
356 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
357 sizeof( IDirectPlayLobby3WImpl ) );
359 if( *ppvObj == NULL )
361 return E_OUTOFMEMORY;
365 ICOM_THIS(IDirectPlayLobby3WImpl,*ppvObj);
367 ICOM_VTBL(This) = &directPlayLobby3WVT;
369 if ( DPL_CreateIUnknown( *ppvObj ) &&
370 DPL_CreateLobby1( *ppvObj ) &&
371 DPL_CreateLobby2( *ppvObj ) &&
372 DPL_CreateLobby3( *ppvObj )
381 else if( IsEqualGUID( &IID_IDirectPlayLobby3A, riid ) )
383 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
384 sizeof( IDirectPlayLobby3AImpl ) );
386 if( *ppvObj == NULL )
388 return E_OUTOFMEMORY;
392 ICOM_THIS(IDirectPlayLobby3AImpl,*ppvObj);
394 ICOM_VTBL(This) = &directPlayLobby3AVT;
396 if ( DPL_CreateIUnknown( *ppvObj ) &&
397 DPL_CreateLobby1( *ppvObj ) &&
398 DPL_CreateLobby2( *ppvObj ) &&
399 DPL_CreateLobby3( *ppvObj )
409 /* Unsupported interface */
411 return E_NOINTERFACE;
415 DPL_DestroyLobby3( *ppvObj );
416 DPL_DestroyLobby2( *ppvObj );
417 DPL_DestroyLobby1( *ppvObj );
418 DPL_DestroyIUnknown( *ppvObj );
419 HeapFree( GetProcessHeap(), 0, *ppvObj );
422 return DPERR_NOMEMORY;
425 static HRESULT WINAPI IDirectPlayLobbyAImpl_QueryInterface
426 ( LPDIRECTPLAYLOBBYA iface,
430 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
431 TRACE("(%p)->(%p,%p)\n", This, riid, ppvObj );
433 if( IsEqualGUID( &IID_IUnknown, riid ) ||
434 IsEqualGUID( &IID_IDirectPlayLobbyA, riid )
437 IDirectPlayLobby_AddRef( iface );
442 return directPlayLobby_QueryInterface( riid, ppvObj );
446 static HRESULT WINAPI IDirectPlayLobbyW_QueryInterface
447 ( LPDIRECTPLAYLOBBY iface,
451 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
452 TRACE("(%p)->(%p,%p)\n", This, riid, ppvObj );
454 if( IsEqualGUID( &IID_IUnknown, riid ) ||
455 IsEqualGUID( &IID_IDirectPlayLobby, riid )
458 IDirectPlayLobby_AddRef( iface );
463 return directPlayLobby_QueryInterface( riid, ppvObj );
467 static HRESULT WINAPI IDirectPlayLobby2AImpl_QueryInterface
468 ( LPDIRECTPLAYLOBBY2A iface,
472 ICOM_THIS(IDirectPlayLobby2AImpl,iface);
473 TRACE("(%p)->(%p,%p)\n", This, riid, ppvObj );
475 /* Compare riids. We know this object is a direct play lobby 2A object.
476 If we are asking about the same type of interface we're fine.
478 if( IsEqualGUID( &IID_IUnknown, riid ) ||
479 IsEqualGUID( &IID_IDirectPlayLobby2A, riid )
482 IDirectPlayLobby_AddRef( iface );
486 return directPlayLobby_QueryInterface( riid, ppvObj );
489 static HRESULT WINAPI IDirectPlayLobby2WImpl_QueryInterface
490 ( LPDIRECTPLAYLOBBY2 iface,
494 ICOM_THIS(IDirectPlayLobby2WImpl,iface);
496 /* Compare riids. We know this object is a direct play lobby 2 object.
497 If we are asking about the same type of interface we're fine.
499 if( IsEqualGUID( &IID_IUnknown, riid ) ||
500 IsEqualGUID( &IID_IDirectPlayLobby2, riid )
503 IDirectPlayLobby_AddRef( iface );
508 return directPlayLobby_QueryInterface( riid, ppvObj );
512 static HRESULT WINAPI IDirectPlayLobby3AImpl_QueryInterface
513 ( LPDIRECTPLAYLOBBY3A iface,
517 ICOM_THIS(IDirectPlayLobby3AImpl,iface);
519 /* Compare riids. We know this object is a direct play lobby 3 object.
520 If we are asking about the same type of interface we're fine.
522 if( IsEqualGUID( &IID_IUnknown, riid ) ||
523 IsEqualGUID( &IID_IDirectPlayLobby3A, riid )
526 IDirectPlayLobby_AddRef( iface );
531 return directPlayLobby_QueryInterface( riid, ppvObj );
535 static HRESULT WINAPI IDirectPlayLobby3WImpl_QueryInterface
536 ( LPDIRECTPLAYLOBBY3 iface,
540 ICOM_THIS(IDirectPlayLobby3WImpl,iface);
542 /* Compare riids. We know this object is a direct play lobby 3 object.
543 If we are asking about the same type of interface we're fine.
545 if( IsEqualGUID( &IID_IUnknown, riid ) ||
546 IsEqualGUID( &IID_IDirectPlayLobby3, riid )
549 IDirectPlayLobby_AddRef( iface );
554 return directPlayLobby_QueryInterface( riid, ppvObj );
559 * Simple procedure. Just increment the reference count to this
560 * structure and return the new reference count.
562 static ULONG WINAPI IDirectPlayLobbyImpl_AddRef
563 ( LPDIRECTPLAYLOBBY iface )
566 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
568 EnterCriticalSection( &This->unk->DPL_lock );
570 refCount = ++(This->unk->ref);
572 LeaveCriticalSection( &This->unk->DPL_lock );
574 TRACE("ref count incremented to %lu for %p\n", refCount, This );
580 * Simple COM procedure. Decrease the reference count to this object.
581 * If the object no longer has any reference counts, free up the associated
584 static ULONG WINAPI IDirectPlayLobbyAImpl_Release
585 ( LPDIRECTPLAYLOBBYA iface )
589 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
591 EnterCriticalSection( &This->unk->DPL_lock );
593 refCount = --(This->unk->ref);
595 LeaveCriticalSection( &This->unk->DPL_lock );
597 TRACE("ref count decremeneted to %lu for %p\n", refCount, This );
599 /* Deallocate if this is the last reference to the object */
602 DPL_DestroyLobby3( This );
603 DPL_DestroyLobby2( This );
604 DPL_DestroyLobby1( This );
605 DPL_DestroyIUnknown( This );
606 HeapFree( GetProcessHeap(), 0, This );
613 /********************************************************************
615 * Connects an application to the session specified by the DPLCONNECTION
616 * structure currently stored with the DirectPlayLobby object.
618 * Returns a IDirectPlay interface.
621 static HRESULT WINAPI IDirectPlayLobbyAImpl_Connect
622 ( LPDIRECTPLAYLOBBYA iface,
624 LPDIRECTPLAY2A* lplpDP,
627 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
629 LPDIRECTPLAY2A lpDirectPlay2A;
630 /* LPDIRECTPLAY3A lpDirectPlay3A; */
631 /* LPDIRECTPLAYLOBBY2A lpDirectPlayLobby2A; */
634 FIXME("(%p)->(0x%08lx,%p,%p): stub\n", This, dwFlags, lplpDP, pUnk );
636 if( dwFlags || pUnk )
638 return DPERR_INVALIDPARAMS;
641 /* Create the DirectPlay interface */
642 if( ( rc = directPlay_QueryInterface( &IID_IDirectPlay2A, (LPVOID*)lplpDP ) ) != DP_OK )
644 ERR("error creating Direct Play 2A interface. Return Code = 0x%lx.\n", rc );
648 lpDirectPlay2A = *lplpDP;
650 /* - Need to call IDirectPlay::EnumConnections with the service provider to get that good information
651 * - Need to call CreateAddress to create the lpConnection param for IDirectPlay::InitializeConnection
652 * - Call IDirectPlay::InitializeConnection
653 * - Call IDirectPlay::Open
656 IDirectPlayLobby_EnumAddress( iface, RunApplicationA_Callback,
657 lpConn->lpAddress, lpConn->dwAddressSize, NULL );
665 static HRESULT WINAPI IDirectPlayLobbyWImpl_Connect
666 ( LPDIRECTPLAYLOBBY iface,
668 LPDIRECTPLAY2* lplpDP,
671 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
672 LPDIRECTPLAY2* directPlay2W;
675 FIXME("(%p)->(0x%08lx,%p,%p): stub\n", This, dwFlags, lplpDP, pUnk );
677 if( dwFlags || pUnk )
679 return DPERR_INVALIDPARAMS;
682 /* Create the DirectPlay interface */
683 if( ( createRC = directPlay_QueryInterface( &IID_IDirectPlay2, (LPVOID*)lplpDP ) ) != DP_OK )
685 ERR("error creating Direct Play 2W interface. Return Code = 0x%lx.\n", createRC );
689 /* This should invoke IDirectPlay3::InitializeConnection IDirectPlay3::Open */
690 directPlay2W = lplpDP;
696 /********************************************************************
698 * Creates a DirectPlay Address, given a service provider-specific network
700 * Returns an address contains the globally unique identifier
701 * (GUID) of the service provider and data that the service provider can
702 * interpret as a network address.
704 * NOTE: It appears that this method is supposed to be really really stupid
705 * with no error checking on the contents.
707 static HRESULT WINAPI IDirectPlayLobbyAImpl_CreateAddress
708 ( LPDIRECTPLAYLOBBYA iface,
710 REFGUID guidDataType,
714 LPDWORD lpdwAddressSize )
716 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
717 lpAddress, lpdwAddressSize, TRUE );
720 static HRESULT WINAPI IDirectPlayLobbyWImpl_CreateAddress
721 ( LPDIRECTPLAYLOBBY iface,
723 REFGUID guidDataType,
727 LPDWORD lpdwAddressSize )
729 return DPL_CreateAddress( guidSP, guidDataType, lpData, dwDataSize,
730 lpAddress, lpdwAddressSize, FALSE );
733 HRESULT DPL_CreateAddress(
735 REFGUID guidDataType,
739 LPDWORD lpdwAddressSize,
740 BOOL bAnsiInterface )
742 const DWORD dwNumAddElements = 2; /* Service Provide & address data type */
743 DPCOMPOUNDADDRESSELEMENT addressElements[ 2 /* dwNumAddElements */ ];
745 TRACE( "(%p)->(%p,%p,0x%08lx,%p,%p,%d)\n", guidSP, guidDataType, lpData, dwDataSize,
746 lpAddress, lpdwAddressSize, bAnsiInterface );
748 addressElements[ 0 ].guidDataType = DPAID_ServiceProvider;
749 addressElements[ 0 ].dwDataSize = sizeof( GUID );
750 addressElements[ 0 ].lpData = (LPVOID)guidSP;
752 addressElements[ 1 ].guidDataType = *guidDataType;
753 addressElements[ 1 ].dwDataSize = dwDataSize;
754 addressElements[ 1 ].lpData = (LPVOID)lpData;
756 /* Call CreateCompoundAddress to cut down on code.
757 NOTE: We can do this because we don't support DPL 1 interfaces! */
758 return DPL_CreateCompoundAddress( addressElements, dwNumAddElements,
759 lpAddress, lpdwAddressSize, bAnsiInterface );
764 /********************************************************************
766 * Parses out chunks from the DirectPlay Address buffer by calling the
767 * given callback function, with lpContext, for each of the chunks.
770 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddress
771 ( LPDIRECTPLAYLOBBYA iface,
772 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
777 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
779 TRACE("(%p)->(%p,%p,0x%08lx,%p)\n", This, lpEnumAddressCallback, lpAddress,
780 dwAddressSize, lpContext );
782 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
785 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddress
786 ( LPDIRECTPLAYLOBBY iface,
787 LPDPENUMADDRESSCALLBACK lpEnumAddressCallback,
792 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
794 TRACE("(%p)->(%p,%p,0x%08lx,%p)\n", This, lpEnumAddressCallback, lpAddress,
795 dwAddressSize, lpContext );
797 return DPL_EnumAddress( lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext );
800 static HRESULT DPL_EnumAddress( LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress,
801 DWORD dwAddressSize, LPVOID lpContext )
803 DWORD dwTotalSizeEnumerated = 0;
805 /* FIXME: First chunk is always the total size chunk - Should we report it? */
807 while ( dwTotalSizeEnumerated < dwAddressSize )
809 LPDPADDRESS lpElements = (LPDPADDRESS)lpAddress;
810 DWORD dwSizeThisEnumeration;
812 /* Invoke the enum method. If false is returned, stop enumeration */
813 if ( !lpEnumAddressCallback( &lpElements->guidDataType, lpElements->dwDataSize,
814 lpElements + sizeof( DPADDRESS ), lpContext ) )
819 dwSizeThisEnumeration = sizeof( DPADDRESS ) + lpElements->dwDataSize;
820 lpAddress = (char *) lpAddress + dwSizeThisEnumeration;
821 dwTotalSizeEnumerated += dwSizeThisEnumeration;
827 /********************************************************************
829 * Enumerates all the address types that a given service provider needs to
830 * build the DirectPlay Address.
833 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumAddressTypes
834 ( LPDIRECTPLAYLOBBYA iface,
835 LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
840 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
843 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Service Providers";
844 DWORD dwIndex, sizeOfSubKeyName=50;
848 TRACE(" (%p)->(%p,%p,%p,0x%08lx)\n", This, lpEnumAddressTypeCallback, guidSP, lpContext, dwFlags );
852 return DPERR_INVALIDPARAMS;
855 if( !lpEnumAddressTypeCallback || !*lpEnumAddressTypeCallback )
857 return DPERR_INVALIDPARAMS;
862 return DPERR_INVALIDOBJECT;
865 /* Need to loop over the service providers in the registry */
866 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
867 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
869 /* Hmmm. Does this mean that there are no service providers? */
870 ERR(": no service providers?\n");
874 /* Traverse all the service providers we have available */
876 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
877 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
878 ++dwIndex, sizeOfSubKeyName=50 )
881 HKEY hkServiceProvider, hkServiceProviderAt;
882 GUID serviceProviderGUID;
883 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
885 char returnBuffer[51];
886 LPWSTR lpWGUIDString;
888 LPSTR atKey = "Address Types";
889 LPSTR guidDataSubKey = "Guid";
893 TRACE(" this time through: %s\n", subKeyName );
895 /* Get a handle for this particular service provider */
896 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
897 &hkServiceProvider ) != ERROR_SUCCESS )
899 ERR(": what the heck is going on?\n" );
903 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
904 NULL, &returnTypeGUID, returnBuffer,
905 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
907 ERR(": missing GUID registry data members\n" );
911 /* FIXME: Check return types to ensure we're interpreting data right */
912 lpWGUIDString = HEAP_strdupAtoW( GetProcessHeap(), 0, returnBuffer );
913 CLSIDFromString( (LPCOLESTR)lpWGUIDString, &serviceProviderGUID );
914 HeapFree( GetProcessHeap(), 0, lpWGUIDString );
915 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
917 /* Determine if this is the Service Provider that the user asked for */
918 if( !IsEqualGUID( &serviceProviderGUID, guidSP ) )
923 /* Get a handle for this particular service provider */
924 if( RegOpenKeyExA( hkServiceProvider, atKey, 0, KEY_READ,
925 &hkServiceProviderAt ) != ERROR_SUCCESS )
927 TRACE(": No Address Types registry data sub key/members\n" );
931 /* Traverse all the address type we have available */
933 RegEnumKeyExA( hkServiceProviderAt, dwAtIndex, atSubKey, &sizeOfSubKeyName,
934 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
935 ++dwAtIndex, sizeOfSubKeyName=50 )
937 TRACE( "Found Address Type GUID %s\n", atSubKey );
939 /* FIXME: Check return types to ensure we're interpreting data right */
940 lpWGUIDString = HEAP_strdupAtoW( GetProcessHeap(), 0, atSubKey );
941 CLSIDFromString( (LPCOLESTR)lpWGUIDString, &serviceProviderGUID );
942 HeapFree( GetProcessHeap(), 0, lpWGUIDString );
943 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
945 /* The enumeration will return FALSE if we are not to continue */
946 if( !lpEnumAddressTypeCallback( &serviceProviderGUID, lpContext, 0 ) )
948 WARN("lpEnumCallback returning FALSE\n" );
949 break; /* FIXME: This most likely has to break from the procedure...*/
954 /* We only enumerate address types for 1 GUID. We've found it, so quit looking */
961 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumAddressTypes
962 ( LPDIRECTPLAYLOBBY iface,
963 LPDPLENUMADDRESSTYPESCALLBACK lpEnumAddressTypeCallback,
969 return DPERR_OUTOFMEMORY;
972 /********************************************************************
974 * Enumerates what applications are registered with DirectPlay by
975 * invoking the callback function with lpContext.
978 static HRESULT WINAPI IDirectPlayLobbyWImpl_EnumLocalApplications
979 ( LPDIRECTPLAYLOBBY iface,
980 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
984 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
986 FIXME("(%p)->(%p,%p,0x%08lx):stub\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
988 return DPERR_OUTOFMEMORY;
991 static HRESULT WINAPI IDirectPlayLobbyAImpl_EnumLocalApplications
992 ( LPDIRECTPLAYLOBBYA iface,
993 LPDPLENUMLOCALAPPLICATIONSCALLBACK lpEnumLocalAppCallback,
997 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1000 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Applications";
1001 LPSTR guidDataSubKey = "Guid";
1002 DWORD dwIndex, sizeOfSubKeyName=50;
1003 char subKeyName[51];
1006 TRACE("(%p)->(%p,%p,0x%08lx)\n", This, lpEnumLocalAppCallback, lpContext, dwFlags );
1010 return DPERR_INVALIDPARAMS;
1013 if( !lpEnumLocalAppCallback || !*lpEnumLocalAppCallback )
1015 return DPERR_INVALIDPARAMS;
1018 /* Need to loop over the service providers in the registry */
1019 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
1020 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
1022 /* Hmmm. Does this mean that there are no service providers? */
1023 ERR(": no service providers?\n");
1027 /* Traverse all registered applications */
1029 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
1030 ++dwIndex, sizeOfSubKeyName=50 )
1033 HKEY hkServiceProvider;
1034 GUID serviceProviderGUID;
1035 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
1036 char returnBuffer[51];
1037 LPWSTR lpWGUIDString;
1038 DPLAPPINFO dplAppInfo;
1040 TRACE(" this time through: %s\n", subKeyName );
1042 /* Get a handle for this particular service provider */
1043 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
1044 &hkServiceProvider ) != ERROR_SUCCESS )
1046 ERR(": what the heck is going on?\n" );
1050 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
1051 NULL, &returnTypeGUID, returnBuffer,
1052 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1054 ERR(": missing GUID registry data members\n" );
1058 /* FIXME: Check return types to ensure we're interpreting data right */
1059 lpWGUIDString = HEAP_strdupAtoW( GetProcessHeap(), 0, returnBuffer );
1060 CLSIDFromString( (LPCOLESTR)lpWGUIDString, &serviceProviderGUID );
1061 HeapFree( GetProcessHeap(), 0, lpWGUIDString );
1062 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
1064 dplAppInfo.dwSize = sizeof( dplAppInfo );
1065 dplAppInfo.guidApplication = serviceProviderGUID;
1066 dplAppInfo.appName.lpszAppNameA = subKeyName;
1068 EnterCriticalSection( &This->unk->DPL_lock );
1070 memcpy( &This->dpl->hkCallbackKeyHack, &hkServiceProvider, sizeof( hkServiceProvider ) );
1072 if( !lpEnumLocalAppCallback( &dplAppInfo, lpContext, dwFlags ) )
1074 LeaveCriticalSection( &This->unk->DPL_lock );
1078 LeaveCriticalSection( &This->unk->DPL_lock );
1084 /********************************************************************
1086 * Retrieves the DPLCONNECTION structure that contains all the information
1087 * needed to start and connect an application. This was generated using
1088 * either the RunApplication or SetConnectionSettings methods.
1090 * NOTES: If lpData is NULL then just return lpdwDataSize. This allows
1091 * the data structure to be allocated by our caller which can then
1092 * call this procedure/method again with a valid data pointer.
1094 static HRESULT WINAPI IDirectPlayLobbyAImpl_GetConnectionSettings
1095 ( LPDIRECTPLAYLOBBYA iface,
1098 LPDWORD lpdwDataSize )
1100 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1103 TRACE("(%p)->(0x%08lx,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
1105 EnterCriticalSection( &This->unk->DPL_lock );
1107 hr = DPLAYX_GetConnectionSettingsA( dwAppID, lpData, lpdwDataSize );
1109 LeaveCriticalSection( &This->unk->DPL_lock );
1114 static HRESULT WINAPI IDirectPlayLobbyWImpl_GetConnectionSettings
1115 ( LPDIRECTPLAYLOBBY iface,
1118 LPDWORD lpdwDataSize )
1120 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1123 TRACE("(%p)->(0x%08lx,%p,%p)\n", This, dwAppID, lpData, lpdwDataSize );
1125 EnterCriticalSection( &This->unk->DPL_lock );
1127 hr = DPLAYX_GetConnectionSettingsW( dwAppID, lpData, lpdwDataSize );
1129 LeaveCriticalSection( &This->unk->DPL_lock );
1134 /********************************************************************
1136 * Retrieves the message sent between a lobby client and a DirectPlay
1137 * application. All messages are queued until received.
1140 static HRESULT WINAPI IDirectPlayLobbyAImpl_ReceiveLobbyMessage
1141 ( LPDIRECTPLAYLOBBYA iface,
1144 LPDWORD lpdwMessageFlags,
1146 LPDWORD lpdwDataSize )
1148 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1149 FIXME(":stub %p %08lx %08lx %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1151 return DPERR_OUTOFMEMORY;
1154 static HRESULT WINAPI IDirectPlayLobbyWImpl_ReceiveLobbyMessage
1155 ( LPDIRECTPLAYLOBBY iface,
1158 LPDWORD lpdwMessageFlags,
1160 LPDWORD lpdwDataSize )
1162 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1163 FIXME(":stub %p %08lx %08lx %p %p %p\n", This, dwFlags, dwAppID, lpdwMessageFlags, lpData,
1165 return DPERR_OUTOFMEMORY;
1168 typedef struct tagRunApplicationEnumStruct
1170 IDirectPlayLobbyAImpl* This;
1175 LPSTR lpszCommandLine;
1176 LPSTR lpszCurrentDirectory;
1177 } RunApplicationEnumStruct, *lpRunApplicationEnumStruct;
1179 /* To be called by RunApplication to find how to invoke the function */
1180 static BOOL CALLBACK RunApplicationA_EnumLocalApplications
1181 ( LPCDPLAPPINFO lpAppInfo,
1185 lpRunApplicationEnumStruct lpData = (lpRunApplicationEnumStruct)lpContext;
1187 if( IsEqualGUID( &lpAppInfo->guidApplication, &lpData->appGUID ) )
1189 char returnBuffer[200];
1190 DWORD returnType, sizeOfReturnBuffer;
1191 LPSTR clSubKey = "CommandLine";
1192 LPSTR cdSubKey = "CurrentDirectory";
1193 LPSTR fileSubKey = "File";
1194 LPSTR pathSubKey = "Path";
1196 /* FIXME: Lazy man hack - dplay struct has the present reg key saved */
1198 sizeOfReturnBuffer = 200;
1200 /* Get all the appropriate data from the registry */
1201 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, clSubKey,
1202 NULL, &returnType, returnBuffer,
1203 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1205 ERR( ": missing CommandLine registry data member\n" );
1209 lpData->lpszCommandLine = HEAP_strdupA( GetProcessHeap(), HEAP_ZERO_MEMORY, returnBuffer );
1212 sizeOfReturnBuffer = 200;
1214 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, cdSubKey,
1215 NULL, &returnType, returnBuffer,
1216 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1218 ERR( ": missing CurrentDirectory registry data member\n" );
1222 lpData->lpszCurrentDirectory = HEAP_strdupA( GetProcessHeap(), HEAP_ZERO_MEMORY, returnBuffer );
1225 sizeOfReturnBuffer = 200;
1227 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, fileSubKey,
1228 NULL, &returnType, returnBuffer,
1229 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1231 ERR( ": missing File registry data member\n" );
1235 lpData->lpszFileName = HEAP_strdupA( GetProcessHeap(), HEAP_ZERO_MEMORY, returnBuffer );
1238 sizeOfReturnBuffer = 200;
1240 if( RegQueryValueExA( lpData->This->dpl->hkCallbackKeyHack, pathSubKey,
1241 NULL, &returnType, returnBuffer,
1242 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
1244 ERR( ": missing Path registry data member\n" );
1248 lpData->lpszPath = HEAP_strdupA( GetProcessHeap(), HEAP_ZERO_MEMORY, returnBuffer );
1251 return FALSE; /* No need to keep going as we found what we wanted */
1254 return TRUE; /* Keep enumerating, haven't found the application yet */
1257 /********************************************************************
1259 * Starts an application and passes to it all the information to
1260 * connect to a session.
1263 static HRESULT WINAPI IDirectPlayLobbyAImpl_RunApplication
1264 ( LPDIRECTPLAYLOBBYA iface,
1267 LPDPLCONNECTION lpConn,
1268 HANDLE hReceiveEvent )
1270 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1272 RunApplicationEnumStruct enumData;
1274 STARTUPINFOA startupInfo;
1275 PROCESS_INFORMATION newProcessInfo;
1278 TRACE( "(%p)->(0x%08lx,%p,%p,%x)\n", This, dwFlags, lpdwAppID, lpConn, hReceiveEvent );
1282 return DPERR_INVALIDPARAMS;
1285 EnterCriticalSection( &This->unk->DPL_lock );
1287 ZeroMemory( &enumData, sizeof( enumData ) );
1288 enumData.This = This;
1289 enumData.appGUID = lpConn->lpSessionDesc->guidApplication;
1291 /* Our callback function will fill up the enumData structure with all the information
1292 required to start a new process */
1293 IDirectPlayLobby_EnumLocalApplications( iface, RunApplicationA_EnumLocalApplications,
1294 (LPVOID)(&enumData), 0 );
1296 /* First the application name */
1297 strcpy( temp, enumData.lpszPath );
1298 strcat( temp, "\\" );
1299 strcat( temp, enumData.lpszFileName );
1300 HeapFree( GetProcessHeap(), 0, enumData.lpszPath );
1301 HeapFree( GetProcessHeap(), 0, enumData.lpszFileName );
1302 appName = HEAP_strdupA( GetProcessHeap(), HEAP_ZERO_MEMORY, temp );
1304 /* Now the command line */
1305 strcat( temp, " " );
1306 strcat( temp, enumData.lpszCommandLine );
1307 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1308 enumData.lpszCommandLine = HEAP_strdupA( GetProcessHeap(), HEAP_ZERO_MEMORY, temp );
1310 ZeroMemory( &startupInfo, sizeof( startupInfo ) );
1311 startupInfo.cb = sizeof( startupInfo );
1312 /* FIXME: Should any fields be filled in? */
1314 ZeroMemory( &newProcessInfo, sizeof( newProcessInfo ) );
1316 if( !CreateProcessA( appName,
1317 enumData.lpszCommandLine,
1321 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE | CREATE_SUSPENDED, /* Creation Flags */
1323 enumData.lpszCurrentDirectory,
1329 FIXME( "Failed to create process for app %s\n", appName );
1331 HeapFree( GetProcessHeap(), 0, appName );
1332 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1333 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1335 return DPERR_CANTCREATEPROCESS;
1338 HeapFree( GetProcessHeap(), 0, appName );
1339 HeapFree( GetProcessHeap(), 0, enumData.lpszCommandLine );
1340 HeapFree( GetProcessHeap(), 0, enumData.lpszCurrentDirectory );
1342 /* Reserve this global application id! */
1343 if( !DPLAYX_CreateLobbyApplication( newProcessInfo.dwProcessId, hReceiveEvent ) )
1345 ERR( "Unable to create global application data\n" );
1348 hr = IDirectPlayLobby_SetConnectionSettings( iface, 0, newProcessInfo.dwProcessId, lpConn );
1352 FIXME( "SetConnectionSettings failure %s\n", DPLAYX_HresultToString( hr ) );
1356 /* Everything seems to have been set correctly, update the dwAppID */
1357 *lpdwAppID = newProcessInfo.dwProcessId;
1359 /* Unsuspend the process */
1360 ResumeThread( newProcessInfo.dwThreadId );
1362 LeaveCriticalSection( &This->unk->DPL_lock );
1367 static HRESULT WINAPI IDirectPlayLobbyWImpl_RunApplication
1368 ( LPDIRECTPLAYLOBBY iface,
1371 LPDPLCONNECTION lpConn,
1372 HANDLE hReceiveEvent )
1374 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1375 FIXME( "(%p)->(0x%08lx,%p,%p,%p):stub\n", This, dwFlags, lpdwAppID, lpConn, (void *)hReceiveEvent );
1376 return DPERR_OUTOFMEMORY;
1379 /********************************************************************
1381 * Sends a message between the application and the lobby client.
1382 * All messages are queued until received.
1385 static HRESULT WINAPI IDirectPlayLobbyAImpl_SendLobbyMessage
1386 ( LPDIRECTPLAYLOBBYA iface,
1393 return DPERR_OUTOFMEMORY;
1396 static HRESULT WINAPI IDirectPlayLobbyWImpl_SendLobbyMessage
1397 ( LPDIRECTPLAYLOBBY iface,
1404 return DPERR_OUTOFMEMORY;
1407 /********************************************************************
1409 * Modifies the DPLCONNECTION structure to contain all information
1410 * needed to start and connect an application.
1413 static HRESULT WINAPI IDirectPlayLobbyWImpl_SetConnectionSettings
1414 ( LPDIRECTPLAYLOBBY iface,
1417 LPDPLCONNECTION lpConn )
1419 ICOM_THIS(IDirectPlayLobbyWImpl,iface);
1422 TRACE("(%p)->(0x%08lx,0x%08lx,%p)\n", This, dwFlags, dwAppID, lpConn );
1424 EnterCriticalSection( &This->unk->DPL_lock );
1426 hr = DPLAYX_SetConnectionSettingsW( dwFlags, dwAppID, lpConn );
1428 LeaveCriticalSection( &This->unk->DPL_lock );
1433 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetConnectionSettings
1434 ( LPDIRECTPLAYLOBBYA iface,
1437 LPDPLCONNECTION lpConn )
1439 ICOM_THIS(IDirectPlayLobbyAImpl,iface);
1442 TRACE("(%p)->(0x%08lx,0x%08lx,%p)\n", This, dwFlags, dwAppID, lpConn );
1444 EnterCriticalSection( &This->unk->DPL_lock );
1446 hr = DPLAYX_SetConnectionSettingsA( dwFlags, dwAppID, lpConn );
1448 LeaveCriticalSection( &This->unk->DPL_lock );
1453 /********************************************************************
1455 * Registers an event that will be set when a lobby message is received.
1458 static HRESULT WINAPI IDirectPlayLobbyAImpl_SetLobbyMessageEvent
1459 ( LPDIRECTPLAYLOBBYA iface,
1462 HANDLE hReceiveEvent )
1465 return DPERR_OUTOFMEMORY;
1468 static HRESULT WINAPI IDirectPlayLobbyWImpl_SetLobbyMessageEvent
1469 ( LPDIRECTPLAYLOBBY iface,
1472 HANDLE hReceiveEvent )
1475 return DPERR_OUTOFMEMORY;
1481 /********************************************************************
1483 * Registers an event that will be set when a lobby message is received.
1486 static HRESULT WINAPI IDirectPlayLobby2WImpl_CreateCompoundAddress
1487 ( LPDIRECTPLAYLOBBY2 iface,
1488 LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1489 DWORD dwElementCount,
1491 LPDWORD lpdwAddressSize )
1493 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, FALSE );
1496 static HRESULT WINAPI IDirectPlayLobby2AImpl_CreateCompoundAddress
1497 ( LPDIRECTPLAYLOBBY2A iface,
1498 LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1499 DWORD dwElementCount,
1501 LPDWORD lpdwAddressSize )
1503 return DPL_CreateCompoundAddress( lpElements, dwElementCount, lpAddress, lpdwAddressSize, TRUE );
1506 HRESULT DPL_CreateCompoundAddress
1507 ( LPCDPCOMPOUNDADDRESSELEMENT lpElements,
1508 DWORD dwElementCount,
1510 LPDWORD lpdwAddressSize,
1511 BOOL bAnsiInterface )
1513 DWORD dwSizeRequired = 0;
1515 LPCDPCOMPOUNDADDRESSELEMENT lpOrigElements = lpElements;
1517 TRACE("(%p,0x%08lx,%p,%p)\n", lpElements, dwElementCount, lpAddress, lpdwAddressSize );
1519 /* Parameter check */
1520 if( ( lpElements == NULL ) ||
1521 ( dwElementCount == 0 ) /* FIXME: Not sure if this is a failure case */
1524 return DPERR_INVALIDPARAMS;
1527 /* Add the total size chunk */
1528 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DWORD );
1530 /* Calculate the size of the buffer required */
1531 for ( dwElements = dwElementCount; dwElements > 0; --dwElements, ++lpElements )
1533 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1534 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1537 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( GUID );
1539 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1540 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1541 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1544 if( !bAnsiInterface )
1546 ERR( "Ansi GUIDs used for unicode interface\n" );
1547 return DPERR_INVALIDFLAGS;
1550 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize;
1552 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1553 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1554 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1557 if( bAnsiInterface )
1559 ERR( "Unicode GUIDs used for ansi interface\n" );
1560 return DPERR_INVALIDFLAGS;
1563 FIXME( "Right size for unicode interface?\n" );
1564 dwSizeRequired += sizeof( DPADDRESS ) + lpElements->dwDataSize * sizeof( WCHAR );
1566 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1568 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( WORD );
1570 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1572 FIXME( "Right size for unicode interface?\n" );
1573 dwSizeRequired += sizeof( DPADDRESS ) + sizeof( DPCOMPORTADDRESS ); /* FIXME: Right size? */
1577 ERR( "Unknown GUID %s\n", debugstr_guid(&lpElements->guidDataType) );
1578 return DPERR_INVALIDFLAGS;
1582 /* The user wants to know how big a buffer to allocate for us */
1583 if( ( lpAddress == NULL ) ||
1584 ( *lpdwAddressSize < dwSizeRequired )
1587 *lpdwAddressSize = dwSizeRequired;
1588 return DPERR_BUFFERTOOSMALL;
1591 /* Add the total size chunk */
1593 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1595 lpdpAddress->guidDataType = DPAID_TotalSize;
1596 lpdpAddress->dwDataSize = sizeof( DWORD );
1597 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1599 *(LPDWORD)lpAddress = dwSizeRequired;
1600 lpAddress = (char *) lpAddress + sizeof( DWORD );
1603 /* Calculate the size of the buffer required */
1604 for( dwElements = dwElementCount, lpElements = lpOrigElements;
1606 --dwElements, ++lpElements )
1608 if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ServiceProvider ) ) ||
1609 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_LobbyProvider ) )
1612 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1614 lpdpAddress->guidDataType = lpElements->guidDataType;
1615 lpdpAddress->dwDataSize = sizeof( GUID );
1616 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1618 *((LPGUID)lpAddress) = *((LPGUID)lpElements->lpData);
1619 lpAddress = (char *) lpAddress + sizeof( GUID );
1621 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Phone ) ) ||
1622 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_Modem ) ) ||
1623 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INet ) )
1626 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1628 lpdpAddress->guidDataType = lpElements->guidDataType;
1629 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1630 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1632 lstrcpynA( (LPSTR)lpAddress,
1633 (LPCSTR)lpElements->lpData,
1634 lpElements->dwDataSize );
1635 lpAddress = (char *) lpAddress + lpElements->dwDataSize;
1637 else if ( ( IsEqualGUID( &lpElements->guidDataType, &DPAID_PhoneW ) ) ||
1638 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ModemW ) ) ||
1639 ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetW ) )
1642 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1644 lpdpAddress->guidDataType = lpElements->guidDataType;
1645 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1646 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1648 lstrcpynW( (LPWSTR)lpAddress,
1649 (LPCWSTR)lpElements->lpData,
1650 lpElements->dwDataSize );
1651 lpAddress = (char *) lpAddress + lpElements->dwDataSize * sizeof( WCHAR );
1653 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_INetPort ) )
1655 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1657 lpdpAddress->guidDataType = lpElements->guidDataType;
1658 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1659 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1661 *((LPWORD)lpAddress) = *((LPWORD)lpElements->lpData);
1662 lpAddress = (char *) lpAddress + sizeof( WORD );
1664 else if ( IsEqualGUID( &lpElements->guidDataType, &DPAID_ComPort ) )
1666 LPDPADDRESS lpdpAddress = (LPDPADDRESS)lpAddress;
1668 lpdpAddress->guidDataType = lpElements->guidDataType;
1669 lpdpAddress->dwDataSize = lpElements->dwDataSize;
1670 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1672 memcpy( lpAddress, lpElements->lpData, sizeof( DPADDRESS ) );
1673 lpAddress = (char *) lpAddress + sizeof( DPADDRESS );
1682 static HRESULT WINAPI IDirectPlayLobby3WImpl_ConnectEx
1683 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFIID riid, LPVOID* lplpDP, IUnknown* pUnk )
1689 static HRESULT WINAPI IDirectPlayLobby3AImpl_ConnectEx
1690 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, REFIID riid, LPVOID* lplpDP, IUnknown* pUnk )
1696 static HRESULT WINAPI IDirectPlayLobby3WImpl_RegisterApplication
1697 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
1703 static HRESULT WINAPI IDirectPlayLobby3AImpl_RegisterApplication
1704 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
1710 static HRESULT WINAPI IDirectPlayLobby3WImpl_UnregisterApplication
1711 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags, REFGUID lpAppDesc )
1717 static HRESULT WINAPI IDirectPlayLobby3AImpl_UnregisterApplication
1718 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags, REFGUID lpAppDesc )
1724 static HRESULT WINAPI IDirectPlayLobby3WImpl_WaitForConnectionSettings
1725 ( LPDIRECTPLAYLOBBY3 iface, DWORD dwFlags )
1731 static HRESULT WINAPI IDirectPlayLobby3AImpl_WaitForConnectionSettings
1732 ( LPDIRECTPLAYLOBBY3A iface, DWORD dwFlags )
1739 /* Virtual Table definitions for DPL{1,2,3}{A,W} */
1741 /* Note: Hack so we can reuse the old functions without compiler warnings */
1742 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1743 # define XCAST(fun) (typeof(directPlayLobbyAVT.fn##fun))
1745 # define XCAST(fun) (void*)
1748 /* Direct Play Lobby 1 (ascii) Virtual Table for methods */
1749 /* All lobby 1 methods are exactly the same except QueryInterface */
1750 static struct ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyAVT =
1752 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1754 IDirectPlayLobbyAImpl_QueryInterface,
1755 XCAST(AddRef)IDirectPlayLobbyImpl_AddRef,
1756 XCAST(Release)IDirectPlayLobbyAImpl_Release,
1758 IDirectPlayLobbyAImpl_Connect,
1759 IDirectPlayLobbyAImpl_CreateAddress,
1760 IDirectPlayLobbyAImpl_EnumAddress,
1761 IDirectPlayLobbyAImpl_EnumAddressTypes,
1762 IDirectPlayLobbyAImpl_EnumLocalApplications,
1763 IDirectPlayLobbyAImpl_GetConnectionSettings,
1764 IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1765 IDirectPlayLobbyAImpl_RunApplication,
1766 IDirectPlayLobbyAImpl_SendLobbyMessage,
1767 IDirectPlayLobbyAImpl_SetConnectionSettings,
1768 IDirectPlayLobbyAImpl_SetLobbyMessageEvent
1773 /* Note: Hack so we can reuse the old functions without compiler warnings */
1774 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1775 # define XCAST(fun) (typeof(directPlayLobbyWVT.fn##fun))
1777 # define XCAST(fun) (void*)
1780 /* Direct Play Lobby 1 (unicode) Virtual Table for methods */
1781 static ICOM_VTABLE(IDirectPlayLobby) directPlayLobbyWVT =
1783 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1785 IDirectPlayLobbyW_QueryInterface,
1786 XCAST(AddRef)IDirectPlayLobbyImpl_AddRef,
1787 XCAST(Release)IDirectPlayLobbyAImpl_Release,
1789 IDirectPlayLobbyWImpl_Connect,
1790 IDirectPlayLobbyWImpl_CreateAddress,
1791 IDirectPlayLobbyWImpl_EnumAddress,
1792 IDirectPlayLobbyWImpl_EnumAddressTypes,
1793 IDirectPlayLobbyWImpl_EnumLocalApplications,
1794 IDirectPlayLobbyWImpl_GetConnectionSettings,
1795 IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1796 IDirectPlayLobbyWImpl_RunApplication,
1797 IDirectPlayLobbyWImpl_SendLobbyMessage,
1798 IDirectPlayLobbyWImpl_SetConnectionSettings,
1799 IDirectPlayLobbyWImpl_SetLobbyMessageEvent
1803 /* Note: Hack so we can reuse the old functions without compiler warnings */
1804 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1805 # define XCAST(fun) (typeof(directPlayLobby2AVT.fn##fun))
1807 # define XCAST(fun) (void*)
1810 /* Direct Play Lobby 2 (ascii) Virtual Table for methods */
1811 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2AVT =
1813 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1815 IDirectPlayLobby2AImpl_QueryInterface,
1816 XCAST(AddRef)IDirectPlayLobbyImpl_AddRef,
1817 XCAST(Release)IDirectPlayLobbyAImpl_Release,
1819 XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
1820 XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
1821 XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
1822 XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
1823 XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
1824 XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
1825 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1826 XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
1827 XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
1828 XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
1829 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,
1831 IDirectPlayLobby2AImpl_CreateCompoundAddress
1835 /* Note: Hack so we can reuse the old functions without compiler warnings */
1836 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1837 # define XCAST(fun) (typeof(directPlayLobby2AVT.fn##fun))
1839 # define XCAST(fun) (void*)
1842 /* Direct Play Lobby 2 (unicode) Virtual Table for methods */
1843 static ICOM_VTABLE(IDirectPlayLobby2) directPlayLobby2WVT =
1845 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1847 IDirectPlayLobby2WImpl_QueryInterface,
1848 XCAST(AddRef)IDirectPlayLobbyImpl_AddRef,
1849 XCAST(Release)IDirectPlayLobbyAImpl_Release,
1851 XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
1852 XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
1853 XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
1854 XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
1855 XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
1856 XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
1857 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1858 XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
1859 XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
1860 XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
1861 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,
1863 IDirectPlayLobby2WImpl_CreateCompoundAddress
1867 /* Direct Play Lobby 3 (ascii) Virtual Table for methods */
1869 /* Note: Hack so we can reuse the old functions without compiler warnings */
1870 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1871 # define XCAST(fun) (typeof(directPlayLobby3AVT.fn##fun))
1873 # define XCAST(fun) (void*)
1876 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3AVT =
1878 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1879 IDirectPlayLobby3AImpl_QueryInterface,
1880 XCAST(AddRef)IDirectPlayLobbyImpl_AddRef,
1881 XCAST(Release)IDirectPlayLobbyAImpl_Release,
1883 XCAST(Connect)IDirectPlayLobbyAImpl_Connect,
1884 XCAST(CreateAddress)IDirectPlayLobbyAImpl_CreateAddress,
1885 XCAST(EnumAddress)IDirectPlayLobbyAImpl_EnumAddress,
1886 XCAST(EnumAddressTypes)IDirectPlayLobbyAImpl_EnumAddressTypes,
1887 XCAST(EnumLocalApplications)IDirectPlayLobbyAImpl_EnumLocalApplications,
1888 XCAST(GetConnectionSettings)IDirectPlayLobbyAImpl_GetConnectionSettings,
1889 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyAImpl_ReceiveLobbyMessage,
1890 XCAST(RunApplication)IDirectPlayLobbyAImpl_RunApplication,
1891 XCAST(SendLobbyMessage)IDirectPlayLobbyAImpl_SendLobbyMessage,
1892 XCAST(SetConnectionSettings)IDirectPlayLobbyAImpl_SetConnectionSettings,
1893 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyAImpl_SetLobbyMessageEvent,
1895 XCAST(CreateCompoundAddress)IDirectPlayLobby2AImpl_CreateCompoundAddress,
1897 IDirectPlayLobby3AImpl_ConnectEx,
1898 IDirectPlayLobby3AImpl_RegisterApplication,
1899 IDirectPlayLobby3AImpl_UnregisterApplication,
1900 IDirectPlayLobby3AImpl_WaitForConnectionSettings
1904 /* Direct Play Lobby 3 (unicode) Virtual Table for methods */
1906 /* Note: Hack so we can reuse the old functions without compiler warnings */
1907 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1908 # define XCAST(fun) (typeof(directPlayLobby3WVT.fn##fun))
1910 # define XCAST(fun) (void*)
1913 static ICOM_VTABLE(IDirectPlayLobby3) directPlayLobby3WVT =
1915 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1916 IDirectPlayLobby3WImpl_QueryInterface,
1917 XCAST(AddRef)IDirectPlayLobbyImpl_AddRef,
1918 XCAST(Release)IDirectPlayLobbyAImpl_Release,
1920 XCAST(Connect)IDirectPlayLobbyWImpl_Connect,
1921 XCAST(CreateAddress)IDirectPlayLobbyWImpl_CreateAddress,
1922 XCAST(EnumAddress)IDirectPlayLobbyWImpl_EnumAddress,
1923 XCAST(EnumAddressTypes)IDirectPlayLobbyWImpl_EnumAddressTypes,
1924 XCAST(EnumLocalApplications)IDirectPlayLobbyWImpl_EnumLocalApplications,
1925 XCAST(GetConnectionSettings)IDirectPlayLobbyWImpl_GetConnectionSettings,
1926 XCAST(ReceiveLobbyMessage)IDirectPlayLobbyWImpl_ReceiveLobbyMessage,
1927 XCAST(RunApplication)IDirectPlayLobbyWImpl_RunApplication,
1928 XCAST(SendLobbyMessage)IDirectPlayLobbyWImpl_SendLobbyMessage,
1929 XCAST(SetConnectionSettings)IDirectPlayLobbyWImpl_SetConnectionSettings,
1930 XCAST(SetLobbyMessageEvent)IDirectPlayLobbyWImpl_SetLobbyMessageEvent,
1932 XCAST(CreateCompoundAddress)IDirectPlayLobby2WImpl_CreateCompoundAddress,
1934 IDirectPlayLobby3WImpl_ConnectEx,
1935 IDirectPlayLobby3WImpl_RegisterApplication,
1936 IDirectPlayLobby3WImpl_UnregisterApplication,
1937 IDirectPlayLobby3WImpl_WaitForConnectionSettings
1942 /*********************************************************
1944 * Direct Play and Direct Play Lobby Interface Implementation
1946 *********************************************************/
1948 /***************************************************************************
1949 * DirectPlayLobbyCreateA (DPLAYX.4)
1952 HRESULT WINAPI DirectPlayLobbyCreateA( LPGUID lpGUIDDSP,
1953 LPDIRECTPLAYLOBBYA *lplpDPL,
1958 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08lx\n",
1959 lpGUIDDSP,lplpDPL,lpUnk,lpData,dwDataSize);
1961 /* Parameter Check: lpGUIDSP, lpUnk & lpData must be NULL. dwDataSize must
1962 * equal 0. These fields are mostly for future expansion.
1964 if ( lpGUIDDSP || lpUnk || lpData || dwDataSize )
1967 return DPERR_INVALIDPARAMS;
1970 return directPlayLobby_QueryInterface( &IID_IDirectPlayLobbyA, (void**)lplpDPL );
1973 /***************************************************************************
1974 * DirectPlayLobbyCreateW (DPLAYX.5)
1977 HRESULT WINAPI DirectPlayLobbyCreateW( LPGUID lpGUIDDSP,
1978 LPDIRECTPLAYLOBBY *lplpDPL,
1983 TRACE("lpGUIDDSP=%p lplpDPL=%p lpUnk=%p lpData=%p dwDataSize=%08lx\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 || lpUnk || lpData || dwDataSize )
1992 ERR("Bad parameters!\n" );
1993 return DPERR_INVALIDPARAMS;
1996 return directPlayLobby_QueryInterface( &IID_IDirectPlayLobby, (void**)lplpDPL );