kernel32/tests: Add a test to check some fields in fake dlls.
[wine.git] / dlls / dpnet / dpnet_main.c
blobcc80ebc07ab1cd1742e36cd16f01e2cb960f021b
1 /*
2 * DirectPlay
3 *
4 * Copyright 2004 Raphael Junqueira
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * 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
22 #include "config.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "objbase.h"
31 #include "oleauto.h"
32 #include "oleidl.h"
33 #include "rpcproxy.h"
34 #include "wine/debug.h"
36 #include "initguid.h"
37 #include "dpnet_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
41 static HINSTANCE instance;
43 static BOOL winsock_loaded = FALSE;
45 static BOOL WINAPI winsock_startup(INIT_ONCE *once, void *param, void **context)
47 WSADATA wsa_data;
48 DWORD res;
50 res = WSAStartup(MAKEWORD(1,1), &wsa_data);
51 if(res == ERROR_SUCCESS)
52 winsock_loaded = TRUE;
53 else
54 ERR("WSAStartup failed: %u\n", res);
55 return TRUE;
58 void init_winsock(void)
60 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
61 InitOnceExecuteOnce(&init_once, winsock_startup, NULL, NULL);
64 /* At process attach */
65 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
67 TRACE("%p,%x,%p\n", hInstDLL, fdwReason, lpvReserved);
69 switch(fdwReason)
71 case DLL_PROCESS_ATTACH:
72 instance = hInstDLL;
73 DisableThreadLibraryCalls(hInstDLL);
74 break;
76 case DLL_PROCESS_DETACH:
77 if (lpvReserved) break;
78 if(winsock_loaded)
79 WSACleanup();
80 break;
82 return TRUE;
85 /***********************************************************************
86 * DirectPlay8Create (DPNET.@)
88 HRESULT WINAPI DirectPlay8Create(REFGUID lpGUID, LPVOID *ppvInt, LPUNKNOWN punkOuter)
90 TRACE("(%s, %p, %p): stub\n", debugstr_guid(lpGUID), ppvInt, punkOuter);
91 return S_OK;
94 /*******************************************************************************
95 * DirectPlay ClassFactory
97 typedef struct
99 /* IUnknown fields */
100 IClassFactory IClassFactory_iface;
101 LONG ref;
102 REFCLSID rclsid;
103 HRESULT (*pfnCreateInstanceFactory)(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj);
104 } IClassFactoryImpl;
106 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
108 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
111 static HRESULT WINAPI DICF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
112 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
114 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
115 return E_NOINTERFACE;
118 static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
119 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
120 return InterlockedIncrement(&This->ref);
123 static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
124 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
125 /* static class, won't be freed */
126 return InterlockedDecrement(&This->ref);
129 static HRESULT WINAPI DICF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
130 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
132 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
133 return This->pfnCreateInstanceFactory(iface, pOuter, riid, ppobj);
136 static HRESULT WINAPI DICF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
137 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
138 FIXME("(%p)->(%d),stub!\n",This,dolock);
139 return S_OK;
142 static const IClassFactoryVtbl DICF_Vtbl = {
143 DICF_QueryInterface,
144 DICF_AddRef,
145 DICF_Release,
146 DICF_CreateInstance,
147 DICF_LockServer
150 static IClassFactoryImpl DPNET_CFS[] = {
151 { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Client, DPNET_CreateDirectPlay8Client },
152 { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Server, DPNET_CreateDirectPlay8Server },
153 { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Peer, DPNET_CreateDirectPlay8Peer },
154 { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8Address, DPNET_CreateDirectPlay8Address },
155 { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8LobbiedApplication, DPNET_CreateDirectPlay8LobbiedApp },
156 { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8LobbyClient, DPNET_CreateDirectPlay8LobbyClient },
157 { { &DICF_Vtbl }, 1, &CLSID_DirectPlay8ThreadPool, DPNET_CreateDirectPlay8ThreadPool},
158 { { NULL }, 0, NULL, NULL }
161 /***********************************************************************
162 * DllCanUnloadNow (DPNET.@)
164 HRESULT WINAPI DllCanUnloadNow(void)
166 return S_FALSE;
169 /***********************************************************************
170 * DllGetClassObject (DPNET.@)
172 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
174 int i = 0;
176 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
178 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
179 *ppv = (LPVOID)&DPNET_CF;
180 IClassFactory_AddRef((IClassFactory*)*ppv);
181 return S_OK;
184 while (NULL != DPNET_CFS[i].rclsid) {
185 if (IsEqualGUID(rclsid, DPNET_CFS[i].rclsid)) {
186 DICF_AddRef(&DPNET_CFS[i].IClassFactory_iface);
187 *ppv = &DPNET_CFS[i];
188 return S_OK;
190 ++i;
193 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
194 return CLASS_E_CLASSNOTAVAILABLE;
197 /***********************************************************************
198 * DllRegisterServer (DPNET.@)
200 HRESULT WINAPI DllRegisterServer(void)
202 return __wine_register_resources( instance );
205 /***********************************************************************
206 * DllUnregisterServer (DPNET.@)
208 HRESULT WINAPI DllUnregisterServer(void)
210 return __wine_unregister_resources( instance );