/* 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 "dplobby8.h"
#include "dplay8_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dplay);

static ICOM_VTABLE(IDirectPlay8LobbiedApplication) directPlay8LobbiedApplicationVT;

HRESULT WINAPI
DirectPlay8LobbiedApplication_QueryInterface(PDIRECTPLAY8LOBBIEDAPPLICATION iface,
                                             REFIID riid, LPVOID *obj)
{
    ICOM_THIS(IDirectPlay8LobbiedApplicationImpl, iface);
    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
    if (IsEqualGUID(&IID_IUnknown, riid) ||
        IsEqualGUID(&IID_IDirectPlay8LobbiedApplication, 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
DirectPlay8LobbiedApplication_AddRef(PDIRECTPLAY8LOBBIEDAPPLICATION iface)
{
    ICOM_THIS(IDirectPlay8LobbiedApplicationImpl, iface);
    TRACE("(%p)->()\n", iface);
    return ++This->ref;
}

ULONG WINAPI
DirectPlay8LobbiedApplication_Release(PDIRECTPLAY8LOBBIEDAPPLICATION iface)
{
    ICOM_THIS(IDirectPlay8LobbiedApplicationImpl, iface);
    TRACE("(%p)->()\n", iface);
    if (--This->ref) return This->ref;

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

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

HRESULT WINAPI
DirectPlay8LobbiedApplication_Initialize(PDIRECTPLAY8LOBBIEDAPPLICATION iface,
                                         const PVOID pvUserContext,
                                         const PFNDPNMESSAGEHANDLER pfn,
                                         DPNHANDLE * const pdpnhConnection,
                                         const DWORD dwFlags)
{
    /*ICOM_THIS(IDirectPlay8LobbiedApplicationImpl, iface);*/
    FIXME("(%p)->(%p, %p, %p, 0x%08lx): stub. Lobbying not supported, you _may_ be able to ignore this\n",
          iface, pvUserContext,
          pfn, pdpnhConnection, dwFlags);
    *pdpnhConnection = (DPNHANDLE)NULL;
    return S_OK;
}

HRESULT
DPNET_CreateDirectPlay8LobbiedApplication(IUnknown *pOuter, REFIID riid, LPVOID *ppobj)
{
    IDirectPlay8LobbiedApplicationImpl *ipDP8LA;
    HRESULT hr;
    TRACE("()\n");
    ipDP8LA = (IDirectPlay8LobbiedApplicationImpl *)
        HeapAlloc(GetProcessHeap(),
                  HEAP_ZERO_MEMORY,
                  sizeof(IDirectPlay8LobbiedApplicationImpl));
    if (ipDP8LA == NULL) return E_OUTOFMEMORY;
    ICOM_VTBL(ipDP8LA) = &directPlay8LobbiedApplicationVT;
    IDirectPlay8LobbiedApplication_AddRef((IDirectPlay8LobbiedApplication *)ipDP8LA);
    TRACE("Created new interface: %p\n", ipDP8LA);
    hr = IDirectPlay8LobbiedApplication_QueryInterface((IDirectPlay8LobbiedApplication *)ipDP8LA, riid, ppobj);
    IDirectPlay8LobbiedApplication_Release((IDirectPlay8LobbiedApplication *)ipDP8LA);
    if (SUCCEEDED(hr))
        return S_OK;
    else
        return E_NOINTERFACE;
}

static ICOM_VTABLE(IDirectPlay8LobbiedApplication) directPlay8LobbiedApplicationVT =
{
    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    DirectPlay8LobbiedApplication_QueryInterface,
    DirectPlay8LobbiedApplication_AddRef,
    DirectPlay8LobbiedApplication_Release,
    DirectPlay8LobbiedApplication_Initialize,
    (void*)0xdead5005, /* RegisterProgram */
    (void*)0xdead5006, /* UnRegisterProgram */
    (void*)0xdead5007, /* Send */
    (void*)0xdead5008, /* SetAppAvailable */
    (void*)0xdead5009, /* UpdateStatus */
    (void*)0xdead500a, /* Close */
    (void*)0xdead500b, /* GetConnectionSettings */
    (void*)0xdead500c  /* SetConnectionSettings */
};

