credui: Add a stub for CredUIInitControls.
[wine.git] / dlls / dinput8 / dinput8_main.c
blob679e7fde72eaebc759b1971dfbed9cf01d29e6f3
1 /* DirectInput 8
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
21 #include "config.h"
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
26 #define COBJMACROS
28 #include "wine/debug.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "objbase.h"
33 #include "rpcproxy.h"
34 #include "dinput.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) {
58 IDirectInputA *pDI;
59 HRESULT hr, hrCo;
61 TRACE("hInst (%p), dwVersion: %d, riid (%s), punkOuter (%p))\n", hinst, dwVersion, debugstr_guid(riid), punkOuter);
63 if (!ppDI)
64 return E_POINTER;
66 if (!IsEqualGUID(&IID_IDirectInput8A, riid) &&
67 !IsEqualGUID(&IID_IDirectInput8W, riid) &&
68 !IsEqualGUID(&IID_IUnknown, riid))
70 *ppDI = NULL;
71 return DIERR_NOINTERFACE;
74 hrCo = CoInitialize(NULL);
76 hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&pDI);
78 /* Ensure balance of calls. */
79 if (SUCCEEDED(hrCo))
80 CoUninitialize();
82 if (FAILED(hr)) {
83 ERR("CoCreateInstance failed with hr = 0x%08x\n", hr);
84 return hr;
87 hr = IDirectInput_QueryInterface(pDI, riid, ppDI);
88 IDirectInput_Release(pDI);
90 if (FAILED(hr))
91 return hr;
93 /* When aggregation is used (punkOuter!=NULL) the application needs to manually call Initialize. */
94 if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8A, riid)) {
95 IDirectInput8A *DI = *ppDI;
97 hr = IDirectInput8_Initialize(DI, hinst, dwVersion);
98 if (FAILED(hr))
100 IDirectInput8_Release(DI);
101 *ppDI = NULL;
102 return hr;
106 if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8W, riid)) {
107 IDirectInput8W *DI = *ppDI;
109 hr = IDirectInput8_Initialize(DI, hinst, dwVersion);
110 if (FAILED(hr))
112 IDirectInput8_Release(DI);
113 *ppDI = NULL;
114 return hr;
118 return S_OK;
121 /*******************************************************************************
122 * DirectInput8 ClassFactory
124 typedef struct
126 /* IUnknown fields */
127 IClassFactory IClassFactory_iface;
128 } IClassFactoryImpl;
130 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
132 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
135 static HRESULT WINAPI DI8CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
136 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
137 FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj);
138 return E_NOINTERFACE;
141 static ULONG WINAPI DI8CF_AddRef(LPCLASSFACTORY iface) {
142 LockModule();
143 return 2;
146 static ULONG WINAPI DI8CF_Release(LPCLASSFACTORY iface) {
147 UnlockModule();
148 return 1;
151 static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
152 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
154 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
155 if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) || IsEqualGUID( &IID_IUnknown, riid )) {
156 IDirectInputA *ppDI;
157 HRESULT hr;
159 hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&ppDI);
160 if (FAILED(hr))
161 return hr;
163 hr = IDirectInput_QueryInterface(ppDI, riid, ppobj);
164 IDirectInput_Release(ppDI);
166 return hr;
169 ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
170 return E_NOINTERFACE;
173 static HRESULT WINAPI DI8CF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
174 TRACE("(%p)->(%d)\n", iface, dolock);
176 if(dolock)
177 LockModule();
178 else
179 UnlockModule();
181 return S_OK;
184 static const IClassFactoryVtbl DI8CF_Vtbl = {
185 DI8CF_QueryInterface,
186 DI8CF_AddRef,
187 DI8CF_Release,
188 DI8CF_CreateInstance,
189 DI8CF_LockServer
191 static IClassFactoryImpl DINPUT8_CF = { { &DI8CF_Vtbl } };
194 /***********************************************************************
195 * DllCanUnloadNow (DINPUT8.@)
197 HRESULT WINAPI DllCanUnloadNow(void)
199 return dll_count == 0 ? S_OK : S_FALSE;
202 /***********************************************************************
203 * DllGetClassObject (DINPUT8.@)
205 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
207 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
208 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
209 *ppv = &DINPUT8_CF;
210 IClassFactory_AddRef((IClassFactory*)*ppv);
211 return S_OK;
214 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
215 return CLASS_E_CLASSNOTAVAILABLE;
218 /***********************************************************************
219 * DllMain
221 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
223 switch (reason)
225 case DLL_PROCESS_ATTACH:
226 instance = hInstDLL;
227 DisableThreadLibraryCalls( hInstDLL );
228 break;
230 return TRUE;
233 /***********************************************************************
234 * DllRegisterServer (DINPUT8.@)
236 HRESULT WINAPI DllRegisterServer(void)
238 return __wine_register_resources( instance );
241 /***********************************************************************
242 * DllUnregisterServer (DINPUT8.@)
244 HRESULT WINAPI DllUnregisterServer(void)
246 return __wine_unregister_resources( instance );