dpnet: Implement IDirectPlay8Address AddComponent.
This commit is contained in:
parent
a192e7f11b
commit
9a5a5a365e
|
@ -29,6 +29,8 @@
|
||||||
#include "wingdi.h"
|
#include "wingdi.h"
|
||||||
#include "winuser.h"
|
#include "winuser.h"
|
||||||
#include "objbase.h"
|
#include "objbase.h"
|
||||||
|
|
||||||
|
#include "wine/unicode.h"
|
||||||
#include "wine/debug.h"
|
#include "wine/debug.h"
|
||||||
|
|
||||||
#include "dplay8.h"
|
#include "dplay8.h"
|
||||||
|
@ -36,6 +38,42 @@
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
|
WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
|
||||||
|
|
||||||
|
|
||||||
|
static inline void *heap_alloc(size_t len)
|
||||||
|
{
|
||||||
|
return HeapAlloc(GetProcessHeap(), 0, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline BOOL heap_free(void *mem)
|
||||||
|
{
|
||||||
|
return HeapFree(GetProcessHeap(), 0, mem);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline LPWSTR heap_strdupW(LPCWSTR str)
|
||||||
|
{
|
||||||
|
LPWSTR ret = NULL;
|
||||||
|
|
||||||
|
if(str) {
|
||||||
|
DWORD size;
|
||||||
|
|
||||||
|
size = (strlenW(str)+1)*sizeof(WCHAR);
|
||||||
|
ret = heap_alloc(size);
|
||||||
|
if(ret)
|
||||||
|
memcpy(ret, str, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *heap_strdupA( const char *str )
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
if (!str) return NULL;
|
||||||
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static inline IDirectPlay8AddressImpl *impl_from_IDirectPlay8Address(IDirectPlay8Address *iface)
|
static inline IDirectPlay8AddressImpl *impl_from_IDirectPlay8Address(IDirectPlay8Address *iface)
|
||||||
{
|
{
|
||||||
return CONTAINING_RECORD(iface, IDirectPlay8AddressImpl, IDirectPlay8Address_iface);
|
return CONTAINING_RECORD(iface, IDirectPlay8AddressImpl, IDirectPlay8Address_iface);
|
||||||
|
@ -72,7 +110,28 @@ static ULONG WINAPI IDirectPlay8AddressImpl_Release(IDirectPlay8Address *iface)
|
||||||
|
|
||||||
TRACE("(%p) ref=%u\n", This, ref);
|
TRACE("(%p) ref=%u\n", This, ref);
|
||||||
|
|
||||||
if (!ref) {
|
if (!ref)
|
||||||
|
{
|
||||||
|
struct component *entry, *entry2;
|
||||||
|
|
||||||
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->components, struct component, entry)
|
||||||
|
{
|
||||||
|
switch(entry->type)
|
||||||
|
{
|
||||||
|
case DPNA_DATATYPE_STRING:
|
||||||
|
heap_free(entry->data.string);
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_STRING_ANSI:
|
||||||
|
heap_free(entry->data.ansi);
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_BINARY:
|
||||||
|
heap_free(entry->data.binary);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, entry);
|
||||||
|
}
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, This);
|
HeapFree(GetProcessHeap(), 0, This);
|
||||||
}
|
}
|
||||||
return ref;
|
return ref;
|
||||||
|
@ -214,9 +273,15 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address *i
|
||||||
static HRESULT WINAPI IDirectPlay8AddressImpl_GetNumComponents(IDirectPlay8Address *iface,
|
static HRESULT WINAPI IDirectPlay8AddressImpl_GetNumComponents(IDirectPlay8Address *iface,
|
||||||
DWORD *pdwNumComponents)
|
DWORD *pdwNumComponents)
|
||||||
{
|
{
|
||||||
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
|
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
|
||||||
TRACE("(%p): stub\n", This);
|
TRACE("(%p): stub\n", This);
|
||||||
return DPN_OK;
|
|
||||||
|
if(!pdwNumComponents)
|
||||||
|
return DPNERR_INVALIDPOINTER;
|
||||||
|
|
||||||
|
*pdwNumComponents = list_count(&This->components);
|
||||||
|
|
||||||
|
return DPN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByName(IDirectPlay8Address *iface,
|
static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByName(IDirectPlay8Address *iface,
|
||||||
|
@ -240,28 +305,74 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address *
|
||||||
const WCHAR *const pwszName, const void* const lpvData, const DWORD dwDataSize,
|
const WCHAR *const pwszName, const void* const lpvData, const DWORD dwDataSize,
|
||||||
const DWORD dwDataType)
|
const DWORD dwDataType)
|
||||||
{
|
{
|
||||||
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
|
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
|
||||||
TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
|
struct component *entry;
|
||||||
|
BOOL found = FALSE;
|
||||||
if (NULL == lpvData) return DPNERR_INVALIDPOINTER;
|
|
||||||
switch (dwDataType) {
|
TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
|
||||||
case DPNA_DATATYPE_DWORD:
|
|
||||||
if (sizeof(DWORD) != dwDataSize) return DPNERR_INVALIDPARAM;
|
if (NULL == lpvData)
|
||||||
TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
|
return DPNERR_INVALIDPOINTER;
|
||||||
break;
|
|
||||||
case DPNA_DATATYPE_GUID:
|
LIST_FOR_EACH_ENTRY(entry, &This->components, struct component, entry)
|
||||||
if (sizeof(GUID) != dwDataSize) return DPNERR_INVALIDPARAM;
|
{
|
||||||
TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
|
if (lstrcmpW(pwszName, entry->name) == 0)
|
||||||
break;
|
{
|
||||||
case DPNA_DATATYPE_STRING:
|
TRACE("Found %s\n", debugstr_w(pwszName));
|
||||||
TRACE("(%p, %u): STRING Type -> %s\n", lpvData, dwDataSize, (const CHAR*) lpvData);
|
found = TRUE;
|
||||||
break;
|
|
||||||
case DPNA_DATATYPE_BINARY:
|
break;
|
||||||
TRACE("(%p, %u): BINARY Type\n", lpvData, dwDataSize);
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
if(!found)
|
||||||
return DPN_OK;
|
{
|
||||||
|
/* Create a new one */
|
||||||
|
entry = heap_alloc(sizeof(struct component));
|
||||||
|
entry->name = heap_strdupW(pwszName);
|
||||||
|
entry->type = dwDataType;
|
||||||
|
|
||||||
|
list_add_tail(&This->components, &entry->entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (dwDataType)
|
||||||
|
{
|
||||||
|
case DPNA_DATATYPE_DWORD:
|
||||||
|
if (sizeof(DWORD) != dwDataSize)
|
||||||
|
return DPNERR_INVALIDPARAM;
|
||||||
|
|
||||||
|
entry->data.value = *(DWORD*)lpvData;
|
||||||
|
TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_GUID:
|
||||||
|
if (sizeof(GUID) != dwDataSize)
|
||||||
|
return DPNERR_INVALIDPARAM;
|
||||||
|
|
||||||
|
entry->data.guid = *(GUID*)lpvData;
|
||||||
|
TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_STRING:
|
||||||
|
heap_free(entry->data.string);
|
||||||
|
|
||||||
|
entry->data.string = heap_strdupW((WCHAR*)lpvData);
|
||||||
|
TRACE("(%p, %u): STRING Type -> %s\n", lpvData, dwDataSize, debugstr_w((WCHAR*)lpvData));
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_STRING_ANSI:
|
||||||
|
heap_free(entry->data.ansi);
|
||||||
|
|
||||||
|
entry->data.ansi = heap_strdupA((CHAR*)lpvData);
|
||||||
|
TRACE("(%p, %u): ANSI STRING Type -> %s\n", lpvData, dwDataSize, (const CHAR*) lpvData);
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_BINARY:
|
||||||
|
heap_free(entry->data.binary);
|
||||||
|
|
||||||
|
entry->data.binary = heap_alloc(dwDataSize);
|
||||||
|
memcpy(entry->data.binary, lpvData, dwDataSize);
|
||||||
|
TRACE("(%p, %u): BINARY Type\n", lpvData, dwDataSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DPN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address *iface, GUID *pDevGuid) {
|
static HRESULT WINAPI IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address *iface, GUID *pDevGuid) {
|
||||||
|
@ -328,6 +439,8 @@ HRESULT DPNET_CreateDirectPlay8Address(IClassFactory *iface, IUnknown *pUnkOuter
|
||||||
client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl;
|
client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl;
|
||||||
client->ref = 1;
|
client->ref = 1;
|
||||||
|
|
||||||
|
list_init(&client->components);
|
||||||
|
|
||||||
ret = IDirectPlay8AddressImpl_QueryInterface(&client->IDirectPlay8Address_iface, riid, ppobj);
|
ret = IDirectPlay8AddressImpl_QueryInterface(&client->IDirectPlay8Address_iface, riid, ppobj);
|
||||||
IDirectPlay8AddressImpl_Release(&client->IDirectPlay8Address_iface);
|
IDirectPlay8AddressImpl_Release(&client->IDirectPlay8Address_iface);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
# error You must include config.h to use this header
|
# error You must include config.h to use this header
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <wine/list.h>
|
||||||
|
|
||||||
#include "dplay8.h"
|
#include "dplay8.h"
|
||||||
#include "dplobby8.h"
|
#include "dplobby8.h"
|
||||||
/*
|
/*
|
||||||
|
@ -60,17 +62,35 @@ struct IDirectPlay8ClientImpl
|
||||||
/* ------------------- */
|
/* ------------------- */
|
||||||
/* IDirectPlay8Address */
|
/* IDirectPlay8Address */
|
||||||
/* ------------------- */
|
/* ------------------- */
|
||||||
|
struct component
|
||||||
|
{
|
||||||
|
struct list entry;
|
||||||
|
|
||||||
|
WCHAR *name;
|
||||||
|
DWORD type;
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
DWORD value; /* DPNA_DATATYPE_DWORD */
|
||||||
|
GUID guid; /* DPNA_DATATYPE_GUID */
|
||||||
|
WCHAR *string; /* DPNA_DATATYPE_STRING */
|
||||||
|
char *ansi; /* DPNA_DATATYPE_STRING_ANSI */
|
||||||
|
void *binary; /* DPNA_DATATYPE_BINARY */
|
||||||
|
} data;
|
||||||
|
};
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* IDirectPlay8Address implementation structure
|
* IDirectPlay8Address implementation structure
|
||||||
*/
|
*/
|
||||||
struct IDirectPlay8AddressImpl
|
struct IDirectPlay8AddressImpl
|
||||||
{
|
{
|
||||||
IDirectPlay8Address IDirectPlay8Address_iface;
|
IDirectPlay8Address IDirectPlay8Address_iface;
|
||||||
LONG ref;
|
LONG ref;
|
||||||
/* IDirectPlay8Address fields */
|
/* IDirectPlay8Address fields */
|
||||||
GUID SP_guid;
|
GUID SP_guid;
|
||||||
BOOL init;
|
BOOL init;
|
||||||
|
|
||||||
|
struct list components;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
|
|
@ -67,6 +67,110 @@ static void create_directplay_address(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void address_addcomponents(void)
|
||||||
|
{
|
||||||
|
static const WCHAR UNKNOWN[] = { 'u','n','k','n','o','w','n',0 };
|
||||||
|
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
|
||||||
|
HRESULT hr;
|
||||||
|
IDirectPlay8Address *localaddr = NULL;
|
||||||
|
|
||||||
|
hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
|
||||||
|
ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
|
||||||
|
if(SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
GUID compguid;
|
||||||
|
DWORD size, type;
|
||||||
|
DWORD components;
|
||||||
|
DWORD i;
|
||||||
|
DWORD namelen = 0;
|
||||||
|
DWORD bufflen = 0;
|
||||||
|
DWORD port = 8888;
|
||||||
|
|
||||||
|
/* We can add any Component to the Address interface not just the predefined ones. */
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID), DPNA_DATATYPE_GUID);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID)+1, DPNA_DATATYPE_GUID);
|
||||||
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
|
||||||
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
size = sizeof(GUID);
|
||||||
|
hr = IDirectPlay8Address_GetComponentByName(localaddr, UNKNOWN, &compguid, &size, &type);
|
||||||
|
todo_wine ok(IsEqualGUID(&compguid, &IID_Random), "incorrect guid\n");
|
||||||
|
ok(size == sizeof(GUID), "incorrect size\n");
|
||||||
|
todo_wine ok(type == DPNA_DATATYPE_GUID, "incorrect type\n");
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_GetNumComponents(localaddr, NULL);
|
||||||
|
ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, &bufflen, &type);
|
||||||
|
todo_wine ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, NULL, NULL, &bufflen, &type);
|
||||||
|
todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, NULL, &type);
|
||||||
|
todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
trace("GetNumComponents=%d\n", components);
|
||||||
|
for(i=0; i < components; i++)
|
||||||
|
{
|
||||||
|
WCHAR *name;
|
||||||
|
void *buffer;
|
||||||
|
|
||||||
|
bufflen = 0;
|
||||||
|
namelen = 0;
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, NULL, &namelen, NULL, &bufflen, &type);
|
||||||
|
todo_wine ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
|
||||||
|
buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufflen);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, name, &namelen, buffer, &bufflen, &type);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
if(hr == S_OK)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case DPNA_DATATYPE_STRING:
|
||||||
|
trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_w(buffer));
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_DWORD:
|
||||||
|
trace("%d: %s: %d\n", i, wine_dbgstr_w(name), *(DWORD*)buffer);
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_GUID:
|
||||||
|
trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_guid( (GUID*)buffer));
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_BINARY:
|
||||||
|
trace("%d: %s: Binary Data %d\n", i, wine_dbgstr_w(name), bufflen);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
trace(" Unknown\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, name);
|
||||||
|
HeapFree(GetProcessHeap(), 0, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
IDirectPlay8Address_Release(localaddr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(address)
|
START_TEST(address)
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
@ -77,6 +181,7 @@ START_TEST(address)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
create_directplay_address();
|
create_directplay_address();
|
||||||
|
address_addcomponents();
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue