3 * Copyright 2002 TransGaming Technologies Inc.
4 * Copyright 2006 Roderick Colenbrander
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
28 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
38 static HINSTANCE instance;
39 static LONG dll_count;
42 * Dll lifetime tracking declaration
44 static void LockModule(void)
46 InterlockedIncrement(&dll_count);
49 static void UnlockModule(void)
51 InterlockedDecrement(&dll_count);
54 /******************************************************************************
55 * DirectInput8Create (DINPUT8.@)
57 HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI, LPUNKNOWN punkOuter) {
60 TRACE("hInst (%p), dwVersion: %d, riid (%s), punkOuter (%p))\n", hinst, dwVersion, debugstr_guid(riid), punkOuter);
62 /* The specified version needs to be dinput8 (0x800) or higher */
64 return DIERR_OLDDIRECTINPUTVERSION;
66 if( !(IsEqualGUID(&IID_IDirectInput8A, riid) || IsEqualGUID(&IID_IDirectInput8W, riid) || IsEqualGUID(&IID_IUnknown, riid)) )
67 return DIERR_INVALIDPARAM;
69 hrCo = CoInitialize(NULL);
71 hr = CoCreateInstance( &CLSID_DirectInput8, punkOuter, CLSCTX_INPROC_SERVER, riid, ppDI);
73 ERR("CoCreateInstance failed with hr = %d\n", hr);
74 return DIERR_INVALIDPARAM;
77 /* ensure balance of calls */
78 if(hrCo == S_OK || hrCo == S_FALSE)
81 /* When aggregation is used (punkOuter!=NULL) the application needs to manually call Initialize. */
82 if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8A, riid)) {
83 LPDIRECTINPUTA DI = *ppDI;
84 IDirectInput8_Initialize(DI, hinst, dwVersion);
87 if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8W, riid)) {
88 LPDIRECTINPUTW DI = *ppDI;
89 IDirectInput8_Initialize(DI, hinst, dwVersion);
95 /*******************************************************************************
96 * DirectInput8 ClassFactory
100 /* IUnknown fields */
101 IClassFactory IClassFactory_iface;
104 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
106 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
109 static HRESULT WINAPI DI8CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
110 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
111 FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj);
112 return E_NOINTERFACE;
115 static ULONG WINAPI DI8CF_AddRef(LPCLASSFACTORY iface) {
120 static ULONG WINAPI DI8CF_Release(LPCLASSFACTORY iface) {
125 static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
126 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
128 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
129 if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) || IsEqualGUID( &IID_IUnknown, riid )) {
130 return DirectInputCreateEx(0, DIRECTINPUT_VERSION, riid, ppobj, pOuter);
133 ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
134 return E_NOINTERFACE;
137 static HRESULT WINAPI DI8CF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
138 TRACE("(%p)->(%d)\n", iface, dolock);
148 static const IClassFactoryVtbl DI8CF_Vtbl = {
149 DI8CF_QueryInterface,
152 DI8CF_CreateInstance,
155 static IClassFactoryImpl DINPUT8_CF = { { &DI8CF_Vtbl } };
158 /***********************************************************************
159 * DllCanUnloadNow (DINPUT8.@)
161 HRESULT WINAPI DllCanUnloadNow(void)
163 return dll_count == 0 ? S_OK : S_FALSE;
166 /***********************************************************************
167 * DllGetClassObject (DINPUT8.@)
169 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
171 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
172 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
174 IClassFactory_AddRef((IClassFactory*)*ppv);
178 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
179 return CLASS_E_CLASSNOTAVAILABLE;
182 /***********************************************************************
185 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
189 case DLL_PROCESS_ATTACH:
191 DisableThreadLibraryCalls( hInstDLL );
197 /***********************************************************************
198 * DllRegisterServer (DINPUT8.@)
200 HRESULT WINAPI DllRegisterServer(void)
202 return __wine_register_resources( instance, NULL );
205 /***********************************************************************
206 * DllUnregisterServer (DINPUT8.@)
208 HRESULT WINAPI DllUnregisterServer(void)
210 return __wine_unregister_resources( instance, NULL );