/* dpnet.dll
 *
 * Copyright 2002, 2003 TransGaming Technologies
 *
 * David Hammerton (david@transgaming.com)
 */

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
#include "objbase.h"
#include "wine/debug.h"
#include "winerror.h"

#include "dplay8.h"
#include "dplay8_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dplay);

static ICOM_VTABLE(IDirectPlay8Client) directPlay8ClientVT;

HRESULT WINAPI DirectPlay8Client_QueryInterface(PDIRECTPLAY8CLIENT iface,
                                                REFIID riid, LPVOID *obj)
{
    ICOM_THIS(IDirectPlay8ClientImpl, iface);
    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
    if (IsEqualGUID(&IID_IUnknown, riid) ||
        IsEqualGUID(&IID_IDirectPlay8Client, riid))
    {
        This->ref++;
        *obj = This;
        return S_OK;
    }
    else
    {
        FIXME("(%p)->(%s, %p): no interface\n", iface, debugstr_guid(riid), obj);
        return E_NOINTERFACE;
    }
}

ULONG WINAPI DirectPlay8Client_AddRef(PDIRECTPLAY8CLIENT iface)
{
    ICOM_THIS(IDirectPlay8ClientImpl, iface);
    TRACE("(%p)->()\n", iface);
    return ++This->ref;
}

ULONG WINAPI DirectPlay8Client_Release(PDIRECTPLAY8CLIENT iface)
{
    ICOM_THIS(IDirectPlay8ClientImpl, iface);
    TRACE("(%p)->()\n", iface);
    if (--This->ref) return This->ref;

    FIXME("destroy this and everything\n");

    HeapFree(GetProcessHeap(), 0, This);
    return 0;
}

HRESULT DPNET_CreateDirectPlay8Client(IUnknown *pOuter, REFIID riid, LPVOID *ppobj)
{
    IDirectPlay8ClientImpl *ipDP8C;
    HRESULT hr;
    TRACE("()\n");
    ipDP8C = (IDirectPlay8ClientImpl *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                                          sizeof(IDirectPlay8ClientImpl));
    if (ipDP8C == NULL) return E_OUTOFMEMORY;
    ICOM_VTBL(ipDP8C) = &directPlay8ClientVT;
    IDirectPlay8Client_AddRef((IDirectPlay8Client *)ipDP8C);
    TRACE("Created new interface: %p\n", ipDP8C);
    hr = IDirectPlay8Client_QueryInterface((IDirectPlay8Client *)ipDP8C, riid, ppobj);
    IDirectPlay8Client_Release((IDirectPlay8Client *)ipDP8C);
    if (SUCCEEDED(hr))
        return S_OK;
    else
        return E_NOINTERFACE;
}

static ICOM_VTABLE(IDirectPlay8Client) directPlay8ClientVT =
{
    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    DirectPlay8Client_QueryInterface,
    DirectPlay8Client_AddRef,
    DirectPlay8Client_Release,
    (void*)0xdead3004, /* Initilize */
    (void*)0xdead3005, /* EnumServiceProviers */
    (void*)0xdead3006, /* EnumHosts */
    (void*)0xdead3007, /* CancelAsyncOperation */
    (void*)0xdead3008, /* Connect */
    (void*)0xdead3009, /* Send */
    (void*)0xdead300a, /* GetSendQueueInfo */
    (void*)0xdead300b, /* GetApplicationDesc */
    (void*)0xdead300c, /* SetClientInfo */
    (void*)0xdead300d, /* GetServerInfo */
    (void*)0xdead300e, /* GetServerAddress */
    (void*)0xdead300f, /* Close */
    (void*)0xdead3010, /* ReturnBuffer */
    (void*)0xdead3011, /* GetCaps */
    (void*)0xdead3012, /* SetCaps */
    (void*)0xdead3013, /* SetSPCaps */
    (void*)0xdead3014, /* GetSPCaps */
    (void*)0xdead3015, /* GetConnectionInfo */
    (void*)0xdead3016  /* RegisterLobby */
};

