dpnet_main.c 6.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 
 * DirectPlay
 * 
 * Copyright 2004 Raphael Junqueira
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25 26 27 28 29
 *
 */


#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "objbase.h"
30 31 32
#include "oleauto.h"
#include "oleidl.h"
#include "rpcproxy.h"
33 34
#include "wine/debug.h"

35
#include "initguid.h"
36 37 38 39
#include "dpnet_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dpnet);

40 41
static HINSTANCE instance;

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
static BOOL winsock_loaded = FALSE;

static BOOL WINAPI winsock_startup(INIT_ONCE *once, void *param, void **context)
{
    WSADATA wsa_data;
    DWORD res;

    res = WSAStartup(MAKEWORD(1,1), &wsa_data);
    if(res == ERROR_SUCCESS)
        winsock_loaded = TRUE;
    else
        ERR("WSAStartup failed: %u\n", res);
    return TRUE;
}

void init_winsock(void)
{
    static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
    InitOnceExecuteOnce(&init_once, winsock_startup, NULL, NULL);
}

63 64 65
/* At process attach */
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    TRACE("%p,%x,%p\n", hInstDLL, fdwReason, lpvReserved);

    switch(fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            instance = hInstDLL;
            DisableThreadLibraryCalls(hInstDLL);
            break;

        case DLL_PROCESS_DETACH:
            if (lpvReserved) break;
            if(winsock_loaded)
                WSACleanup();
            break;
    }
    return TRUE;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
}

/***********************************************************************
 *             DirectPlay8Create (DPNET.@)
 */
HRESULT WINAPI DirectPlay8Create(REFGUID lpGUID, LPVOID *ppvInt, LPUNKNOWN punkOuter)
{
    TRACE("(%s, %p, %p): stub\n", debugstr_guid(lpGUID), ppvInt, punkOuter);
    return S_OK;
}

/*******************************************************************************
 * DirectPlay ClassFactory
 */
typedef struct
{
  /* IUnknown fields */
99 100 101 102
  IClassFactory IClassFactory_iface;
  LONG          ref;
  REFCLSID      rclsid;
  HRESULT       (*pfnCreateInstanceFactory)(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj);
103 104
} IClassFactoryImpl;

105 106 107 108 109
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
  return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
}

110
static HRESULT WINAPI DICF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
111 112
  IClassFactoryImpl *This = impl_from_IClassFactory(iface);

113 114 115 116 117
  FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
  return E_NOINTERFACE;
}

static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
118
  IClassFactoryImpl *This = impl_from_IClassFactory(iface);
119
  return InterlockedIncrement(&This->ref);
120 121 122
}

static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
123
  IClassFactoryImpl *This = impl_from_IClassFactory(iface);
124
  /* static class, won't be  freed */
125
  return InterlockedDecrement(&This->ref);
126 127 128
}

static HRESULT WINAPI DICF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
129 130
  IClassFactoryImpl *This = impl_from_IClassFactory(iface);

131 132 133 134 135
  TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
  return This->pfnCreateInstanceFactory(iface, pOuter, riid, ppobj);
}

static HRESULT WINAPI DICF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
136
  IClassFactoryImpl *This = impl_from_IClassFactory(iface);
137 138 139 140
  FIXME("(%p)->(%d),stub!\n",This,dolock);
  return S_OK;
}

141
static const IClassFactoryVtbl DICF_Vtbl = {
142 143 144 145 146 147 148 149
  DICF_QueryInterface,
  DICF_AddRef,
  DICF_Release,
  DICF_CreateInstance,
  DICF_LockServer
};

static IClassFactoryImpl DPNET_CFS[] = {
150 151 152 153 154
  { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Client,  DPNET_CreateDirectPlay8Client },
  { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Server,  DPNET_CreateDirectPlay8Server },
  { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Peer,    DPNET_CreateDirectPlay8Peer },
  { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Address, DPNET_CreateDirectPlay8Address },
  { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8LobbiedApplication, DPNET_CreateDirectPlay8LobbiedApp },
155
  { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8LobbyClient, DPNET_CreateDirectPlay8LobbyClient },
156 157
  { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8ThreadPool, DPNET_CreateDirectPlay8ThreadPool},
  { { NULL }, 0, NULL, NULL }
158 159 160 161 162
};

/***********************************************************************
 *             DllCanUnloadNow (DPNET.@)
 */
163
HRESULT WINAPI DllCanUnloadNow(void)
164 165 166 167 168 169 170
{
    return S_FALSE;
}

/***********************************************************************
 *		DllGetClassObject (DPNET.@)
 */
171
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
172 173 174
{
    int i = 0;

175
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
176 177 178 179 180 181 182 183 184
    /*
    if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
    	*ppv = (LPVOID)&DPNET_CF;
	IClassFactory_AddRef((IClassFactory*)*ppv);
	return S_OK;
    }
    */
    while (NULL != DPNET_CFS[i].rclsid) {
      if (IsEqualGUID(rclsid, DPNET_CFS[i].rclsid)) {
185
        DICF_AddRef(&DPNET_CFS[i].IClassFactory_iface);
186 187 188 189 190 191
	*ppv = &DPNET_CFS[i];
	return S_OK;
      }
      ++i;
    }

192
    FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
193 194
    return CLASS_E_CLASSNOTAVAILABLE;
}
195 196 197 198 199 200

/***********************************************************************
 *		DllRegisterServer (DPNET.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
201
    return __wine_register_resources( instance );
202 203 204 205 206 207 208
}

/***********************************************************************
 *		DllUnregisterServer (DPNET.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
209
    return __wine_unregister_resources( instance );
210
}