ReactOS  0.4.14-dev-49-gfb4591c
dinput8_main.c
Go to the documentation of this file.
1 /* DirectInput 8
2  *
3  * Copyright 2002 TransGaming Technologies Inc.
4  * Copyright 2006 Roderick Colenbrander
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "config.h"
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
25 
26 #define COBJMACROS
27 
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"
35 
37 
39 static LONG dll_count;
40 
41 /*
42  * Dll lifetime tracking declaration
43  */
44 static void LockModule(void)
45 {
47 }
48 
49 static void UnlockModule(void)
50 {
52 }
53 
54 /******************************************************************************
55  * DirectInput8Create (DINPUT8.@)
56  */
58  IDirectInputA *pDI;
59  HRESULT hr, hrCo;
60 
61  TRACE("hInst (%p), dwVersion: %d, riid (%s), punkOuter (%p)\n", hinst, dwVersion, debugstr_guid(riid), punkOuter);
62 
63  if (!ppDI)
64  return E_POINTER;
65 
66  if (!IsEqualGUID(&IID_IDirectInput8A, riid) &&
67  !IsEqualGUID(&IID_IDirectInput8W, riid) &&
69  {
70  *ppDI = NULL;
71  return DIERR_NOINTERFACE;
72  }
73 
74  hrCo = CoInitialize(NULL);
75 
76  hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&pDI);
77 
78  /* Ensure balance of calls. */
79  if (SUCCEEDED(hrCo))
81 
82  if (FAILED(hr)) {
83  ERR("CoCreateInstance failed with hr = 0x%08x\n", hr);
84  return hr;
85  }
86 
87  hr = IDirectInput_QueryInterface(pDI, riid, ppDI);
89 
90  if (FAILED(hr))
91  return hr;
92 
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;
96 
97  hr = IDirectInput8_Initialize(DI, hinst, dwVersion);
98  if (FAILED(hr))
99  {
101  *ppDI = NULL;
102  return hr;
103  }
104  }
105 
106  if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8W, riid)) {
107  IDirectInput8W *DI = *ppDI;
108 
109  hr = IDirectInput8_Initialize(DI, hinst, dwVersion);
110  if (FAILED(hr))
111  {
113  *ppDI = NULL;
114  return hr;
115  }
116  }
117 
118  return S_OK;
119 }
120 
121 /*******************************************************************************
122  * DirectInput8 ClassFactory
123  */
124 typedef struct
125 {
126  /* IUnknown fields */
127  IClassFactory IClassFactory_iface;
129 
131 {
132  return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
133 }
134 
135 static HRESULT WINAPI DI8CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
137  FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj);
138  return E_NOINTERFACE;
139 }
140 
141 static ULONG WINAPI DI8CF_AddRef(LPCLASSFACTORY iface) {
142  LockModule();
143  return 2;
144 }
145 
146 static ULONG WINAPI DI8CF_Release(LPCLASSFACTORY iface) {
147  UnlockModule();
148  return 1;
149 }
150 
151 static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
153 
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;
158 
159  hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&ppDI);
160  if (FAILED(hr))
161  return hr;
162 
163  hr = IDirectInput_QueryInterface(ppDI, riid, ppobj);
164  IDirectInput_Release(ppDI);
165 
166  return hr;
167  }
168 
169  ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
170  return E_NOINTERFACE;
171 }
172 
173 static HRESULT WINAPI DI8CF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
174  TRACE("(%p)->(%d)\n", iface, dolock);
175 
176  if(dolock)
177  LockModule();
178  else
179  UnlockModule();
180 
181  return S_OK;
182 }
183 
184 static const IClassFactoryVtbl DI8CF_Vtbl = {
186  DI8CF_AddRef,
190 };
192 
193 
194 /***********************************************************************
195  * DllCanUnloadNow (DINPUT8.@)
196  */
198 {
199  return dll_count == 0 ? S_OK : S_FALSE;
200 }
201 
202 /***********************************************************************
203  * DllGetClassObject (DINPUT8.@)
204  */
206 {
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;
212  }
213 
214  FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
216 }
217 
218 /***********************************************************************
219  * DllMain
220  */
222 {
223  switch (reason)
224  {
225  case DLL_PROCESS_ATTACH:
226  instance = hInstDLL;
227  DisableThreadLibraryCalls( hInstDLL );
228  break;
229  }
230  return TRUE;
231 }
232 
233 /***********************************************************************
234  * DllRegisterServer (DINPUT8.@)
235  */
237 {
239 }
240 
241 /***********************************************************************
242  * DllUnregisterServer (DINPUT8.@)
243  */
245 {
247 }
static HINSTANCE instance
Definition: dinput8_main.c:38
static HRESULT WINAPI DI8CF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
Definition: dinput8_main.c:173
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
static ULONG WINAPI DI8CF_AddRef(LPCLASSFACTORY iface)
Definition: dinput8_main.c:141
#define E_NOINTERFACE
Definition: winerror.h:2364
static ULONG WINAPI DI8CF_Release(LPCLASSFACTORY iface)
Definition: dinput8_main.c:146
HRESULT hr
Definition: shlfolder.c:183
HRESULT __wine_register_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:98
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: dinput8_main.c:205
REFIID riid
Definition: precomp.h:44
#define REFCLSID
Definition: guiddef.h:117
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define IDirectInput_QueryInterface(p, a, b)
Definition: dinput.h:2239
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:2663
static HRESULT WINAPI DI8CF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
Definition: dinput8_main.c:135
struct tagIClassFactoryImpl IClassFactoryImpl
static void UnlockModule(void)
Definition: dinput8_main.c:49
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static LPUNKNOWN
Definition: ndr_ole.c:49
#define FIXME(fmt,...)
Definition: debug.h:110
WINE_DEFAULT_DEBUG_CHANNEL(dinput)
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
static IClassFactoryImpl DINPUT8_CF
Definition: dinput8_main.c:191
#define IDirectInput8_Initialize(p, a, b)
Definition: dinput.h:2464
HRESULT WINAPI DllUnregisterServer(void)
Definition: dinput8_main.c:244
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:240
#define TRACE(s)
Definition: solgame.cpp:4
#define IDirectInput_Release(p)
Definition: dinput.h:2241
static LONG dll_count
Definition: dinput8_main.c:39
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
#define InterlockedDecrement
Definition: armddk.h:52
HRESULT __wine_unregister_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:110
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59
HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI, LPUNKNOWN punkOuter)
Definition: dinput8_main.c:57
static IClassFactoryImpl * impl_from_IClassFactory(IClassFactory *iface)
Definition: dinput8_main.c:130
#define InterlockedIncrement
Definition: armddk.h:53
#define DIERR_NOINTERFACE
Definition: dinput.h:153
static void LockModule(void)
Definition: dinput8_main.c:44
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
static const IClassFactoryVtbl DI8CF_Vtbl
Definition: dinput8_main.c:184
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
Definition: dinput8_main.c:221
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
HRESULT WINAPI DllRegisterServer(void)
Definition: dinput8_main.c:236
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1897
unsigned int ULONG
Definition: retypes.h:1
static HINSTANCE hinst
Definition: edit.c:551
#define E_POINTER
Definition: winerror.h:2365
static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
Definition: dinput8_main.c:151
const GUID IID_IClassFactory
HRESULT WINAPI DllCanUnloadNow(void)
Definition: dinput8_main.c:197
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:96
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define IDirectInput8_Release(p)
Definition: dinput.h:2458