3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2002 TransGaming Technologies Inc.
6 * Copyright 2007 Vitaliy Margolen
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * - Tomb Raider 2 Demo:
26 * Playable using keyboard only.
27 * - WingCommander Prophecy Demo:
28 * Doesn't get Input Focus.
30 * - Fallout : works great in X and DGA mode
39 #define NONAMELESSUNION
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
50 #include "dinput_private.h"
51 #include "device_private.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
56 static const IDirectInput7AVtbl ddi7avt
;
57 static const IDirectInput7WVtbl ddi7wvt
;
58 static const IDirectInput8AVtbl ddi8avt
;
59 static const IDirectInput8WVtbl ddi8wvt
;
60 static const IDirectInputJoyConfig8Vtbl JoyConfig8vt
;
62 static inline IDirectInputImpl
*impl_from_IDirectInput7A( IDirectInput7A
*iface
)
64 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInput7A_iface
);
67 static inline IDirectInputImpl
*impl_from_IDirectInput7W( IDirectInput7W
*iface
)
69 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInput7W_iface
);
72 static inline IDirectInputImpl
*impl_from_IDirectInput8A( IDirectInput8A
*iface
)
74 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInput8A_iface
);
77 static inline IDirectInputImpl
*impl_from_IDirectInput8W( IDirectInput8W
*iface
)
79 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInput8W_iface
);
82 static inline IDirectInputDeviceImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
84 return CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
);
86 static inline IDirectInputDeviceImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
88 return CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
);
91 static const struct dinput_device
*dinput_devices
[] =
95 &joystick_linuxinput_device
,
96 &joystick_linux_device
,
99 #define NB_DINPUT_DEVICES (sizeof(dinput_devices)/sizeof(dinput_devices[0]))
101 static HINSTANCE DINPUT_instance
= NULL
;
103 static BOOL
check_hook_thread(void);
104 static CRITICAL_SECTION dinput_hook_crit
;
105 static struct list direct_input_list
= LIST_INIT( direct_input_list
);
107 static HRESULT
initialize_directinput_instance(IDirectInputImpl
*This
, DWORD dwVersion
);
108 static void uninitialize_directinput_instance(IDirectInputImpl
*This
);
110 static HRESULT
create_directinput_instance(REFIID riid
, LPVOID
*ppDI
, IDirectInputImpl
**out
)
112 IDirectInputImpl
*This
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectInputImpl
) );
116 return E_OUTOFMEMORY
;
118 This
->IDirectInput7A_iface
.lpVtbl
= &ddi7avt
;
119 This
->IDirectInput7W_iface
.lpVtbl
= &ddi7wvt
;
120 This
->IDirectInput8A_iface
.lpVtbl
= &ddi8avt
;
121 This
->IDirectInput8W_iface
.lpVtbl
= &ddi8wvt
;
122 This
->IDirectInputJoyConfig8_iface
.lpVtbl
= &JoyConfig8vt
;
124 hr
= IDirectInput_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppDI
);
127 HeapFree( GetProcessHeap(), 0, This
);
131 if (out
) *out
= This
;
135 /******************************************************************************
136 * DirectInputCreateEx (DINPUT.@)
138 HRESULT WINAPI
DirectInputCreateEx(
139 HINSTANCE hinst
, DWORD dwVersion
, REFIID riid
, LPVOID
*ppDI
,
142 IDirectInputImpl
*This
;
145 TRACE("(%p,%04x,%s,%p,%p)\n", hinst
, dwVersion
, debugstr_guid(riid
), ppDI
, punkOuter
);
147 if (IsEqualGUID( &IID_IDirectInputA
, riid
) ||
148 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
149 IsEqualGUID( &IID_IDirectInput7A
, riid
) ||
150 IsEqualGUID( &IID_IDirectInputW
, riid
) ||
151 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
152 IsEqualGUID( &IID_IDirectInput7W
, riid
))
154 hr
= create_directinput_instance(riid
, ppDI
, &This
);
159 return DIERR_NOINTERFACE
;
161 hr
= IDirectInput_Initialize( &This
->IDirectInput7A_iface
, hinst
, dwVersion
);
164 IDirectInput_Release( &This
->IDirectInput7A_iface
);
172 /******************************************************************************
173 * DirectInputCreateA (DINPUT.@)
175 HRESULT WINAPI DECLSPEC_HOTPATCH
DirectInputCreateA(HINSTANCE hinst
, DWORD dwVersion
, LPDIRECTINPUTA
*ppDI
, LPUNKNOWN punkOuter
)
177 return DirectInputCreateEx(hinst
, dwVersion
, &IID_IDirectInput7A
, (LPVOID
*)ppDI
, punkOuter
);
180 /******************************************************************************
181 * DirectInputCreateW (DINPUT.@)
183 HRESULT WINAPI DECLSPEC_HOTPATCH
DirectInputCreateW(HINSTANCE hinst
, DWORD dwVersion
, LPDIRECTINPUTW
*ppDI
, LPUNKNOWN punkOuter
)
185 return DirectInputCreateEx(hinst
, dwVersion
, &IID_IDirectInput7W
, (LPVOID
*)ppDI
, punkOuter
);
188 static const char *_dump_DIDEVTYPE_value(DWORD dwDevType
) {
190 case 0: return "All devices";
191 case DIDEVTYPE_MOUSE
: return "DIDEVTYPE_MOUSE";
192 case DIDEVTYPE_KEYBOARD
: return "DIDEVTYPE_KEYBOARD";
193 case DIDEVTYPE_JOYSTICK
: return "DIDEVTYPE_JOYSTICK";
194 case DIDEVTYPE_DEVICE
: return "DIDEVTYPE_DEVICE";
195 default: return "Unknown";
199 static void _dump_EnumDevices_dwFlags(DWORD dwFlags
) {
200 if (TRACE_ON(dinput
)) {
202 static const struct {
206 #define FE(x) { x, #x}
207 FE(DIEDFL_ALLDEVICES
),
208 FE(DIEDFL_ATTACHEDONLY
),
209 FE(DIEDFL_FORCEFEEDBACK
),
210 FE(DIEDFL_INCLUDEALIASES
),
211 FE(DIEDFL_INCLUDEPHANTOMS
),
212 FE(DIEDFL_INCLUDEHIDDEN
)
217 TRACE("DIEDFL_ALLDEVICES\n");
220 for (i
= 0; i
< (sizeof(flags
) / sizeof(flags
[0])); i
++)
221 if (flags
[i
].mask
& dwFlags
)
222 TRACE("%s ",flags
[i
].name
);
227 static void _dump_diactionformatA(LPDIACTIONFORMATA lpdiActionFormat
) {
230 FIXME("diaf.dwSize = %d\n", lpdiActionFormat
->dwSize
);
231 FIXME("diaf.dwActionSize = %d\n", lpdiActionFormat
->dwActionSize
);
232 FIXME("diaf.dwDataSize = %d\n", lpdiActionFormat
->dwDataSize
);
233 FIXME("diaf.dwNumActions = %d\n", lpdiActionFormat
->dwNumActions
);
234 FIXME("diaf.rgoAction = %p\n", lpdiActionFormat
->rgoAction
);
235 FIXME("diaf.guidActionMap = %s\n", debugstr_guid(&lpdiActionFormat
->guidActionMap
));
236 FIXME("diaf.dwGenre = 0x%08x\n", lpdiActionFormat
->dwGenre
);
237 FIXME("diaf.dwBufferSize = %d\n", lpdiActionFormat
->dwBufferSize
);
238 FIXME("diaf.lAxisMin = %d\n", lpdiActionFormat
->lAxisMin
);
239 FIXME("diaf.lAxisMax = %d\n", lpdiActionFormat
->lAxisMax
);
240 FIXME("diaf.hInstString = %p\n", lpdiActionFormat
->hInstString
);
241 FIXME("diaf.ftTimeStamp ...\n");
242 FIXME("diaf.dwCRC = 0x%x\n", lpdiActionFormat
->dwCRC
);
243 FIXME("diaf.tszActionMap = %s\n", debugstr_a(lpdiActionFormat
->tszActionMap
));
244 for (i
= 0; i
< lpdiActionFormat
->dwNumActions
; i
++)
246 FIXME("diaf.rgoAction[%u]:\n", i
);
247 FIXME("\tuAppData=0x%lx\n", lpdiActionFormat
->rgoAction
[i
].uAppData
);
248 FIXME("\tdwSemantic=0x%08x\n", lpdiActionFormat
->rgoAction
[i
].dwSemantic
);
249 FIXME("\tdwFlags=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwFlags
);
250 FIXME("\tszActionName=%s\n", debugstr_a(lpdiActionFormat
->rgoAction
[i
].u
.lptszActionName
));
251 FIXME("\tguidInstance=%s\n", debugstr_guid(&lpdiActionFormat
->rgoAction
[i
].guidInstance
));
252 FIXME("\tdwObjID=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwObjID
);
253 FIXME("\tdwHow=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwHow
);
257 void _copy_diactionformatAtoW(LPDIACTIONFORMATW to
, LPDIACTIONFORMATA from
)
261 to
->dwSize
= sizeof(DIACTIONFORMATW
);
262 to
->dwActionSize
= sizeof(DIACTIONW
);
263 to
->dwDataSize
= from
->dwDataSize
;
264 to
->dwNumActions
= from
->dwNumActions
;
265 to
->guidActionMap
= from
->guidActionMap
;
266 to
->dwGenre
= from
->dwGenre
;
267 to
->dwBufferSize
= from
->dwBufferSize
;
268 to
->lAxisMin
= from
->lAxisMin
;
269 to
->lAxisMax
= from
->lAxisMax
;
270 to
->dwCRC
= from
->dwCRC
;
271 to
->ftTimeStamp
= from
->ftTimeStamp
;
273 for (i
=0; i
< to
->dwNumActions
; i
++)
275 to
->rgoAction
[i
].uAppData
= from
->rgoAction
[i
].uAppData
;
276 to
->rgoAction
[i
].dwSemantic
= from
->rgoAction
[i
].dwSemantic
;
277 to
->rgoAction
[i
].dwFlags
= from
->rgoAction
[i
].dwFlags
;
278 to
->rgoAction
[i
].guidInstance
= from
->rgoAction
[i
].guidInstance
;
279 to
->rgoAction
[i
].dwObjID
= from
->rgoAction
[i
].dwObjID
;
280 to
->rgoAction
[i
].dwHow
= from
->rgoAction
[i
].dwHow
;
284 void _copy_diactionformatWtoA(LPDIACTIONFORMATA to
, LPDIACTIONFORMATW from
)
288 to
->dwSize
= sizeof(DIACTIONFORMATA
);
289 to
->dwActionSize
= sizeof(DIACTIONA
);
290 to
->dwDataSize
= from
->dwDataSize
;
291 to
->dwNumActions
= from
->dwNumActions
;
292 to
->guidActionMap
= from
->guidActionMap
;
293 to
->dwGenre
= from
->dwGenre
;
294 to
->dwBufferSize
= from
->dwBufferSize
;
295 to
->lAxisMin
= from
->lAxisMin
;
296 to
->lAxisMax
= from
->lAxisMax
;
297 to
->dwCRC
= from
->dwCRC
;
298 to
->ftTimeStamp
= from
->ftTimeStamp
;
300 for (i
=0; i
< to
->dwNumActions
; i
++)
302 to
->rgoAction
[i
].uAppData
= from
->rgoAction
[i
].uAppData
;
303 to
->rgoAction
[i
].dwSemantic
= from
->rgoAction
[i
].dwSemantic
;
304 to
->rgoAction
[i
].dwFlags
= from
->rgoAction
[i
].dwFlags
;
305 to
->rgoAction
[i
].guidInstance
= from
->rgoAction
[i
].guidInstance
;
306 to
->rgoAction
[i
].dwObjID
= from
->rgoAction
[i
].dwObjID
;
307 to
->rgoAction
[i
].dwHow
= from
->rgoAction
[i
].dwHow
;
311 /* diactionformat_priority
313 * Given a DIACTIONFORMAT structure and a DI genre, returns the enumeration
314 * priority. Joysticks should pass the game genre, and mouse or keyboard their
315 * respective DI*_MASK
317 static DWORD
diactionformat_priorityA(LPDIACTIONFORMATA lpdiaf
, DWORD genre
)
320 DWORD priorityFlags
= 0;
322 /* If there's at least one action for the device it's priority 1 */
323 for(i
=0; i
< lpdiaf
->dwNumActions
; i
++)
324 if ((lpdiaf
->rgoAction
[i
].dwSemantic
& genre
) == genre
)
325 priorityFlags
|= DIEDBS_MAPPEDPRI1
;
327 return priorityFlags
;
330 static DWORD
diactionformat_priorityW(LPDIACTIONFORMATW lpdiaf
, DWORD genre
)
333 DWORD priorityFlags
= 0;
335 /* If there's at least one action for the device it's priority 1 */
336 for(i
=0; i
< lpdiaf
->dwNumActions
; i
++)
337 if ((lpdiaf
->rgoAction
[i
].dwSemantic
& genre
) == genre
)
338 priorityFlags
|= DIEDBS_MAPPEDPRI1
;
340 return priorityFlags
;
343 /******************************************************************************
344 * IDirectInputA_EnumDevices
346 static HRESULT WINAPI
IDirectInputAImpl_EnumDevices(
347 LPDIRECTINPUT7A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
348 LPVOID pvRef
, DWORD dwFlags
)
350 IDirectInputImpl
*This
= impl_from_IDirectInput7A(iface
);
351 DIDEVICEINSTANCEA devInstance
;
355 TRACE("(this=%p,0x%04x '%s',%p,%p,%04x)\n",
356 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
),
357 lpCallback
, pvRef
, dwFlags
);
358 _dump_EnumDevices_dwFlags(dwFlags
);
361 dwFlags
& ~(DIEDFL_ATTACHEDONLY
| DIEDFL_FORCEFEEDBACK
| DIEDFL_INCLUDEALIASES
| DIEDFL_INCLUDEPHANTOMS
| DIEDFL_INCLUDEHIDDEN
) ||
362 (dwDevType
> DI8DEVCLASS_GAMECTRL
&& dwDevType
< DI8DEVTYPE_DEVICE
) || dwDevType
> DI8DEVTYPE_SUPPLEMENTAL
)
363 return DIERR_INVALIDPARAM
;
365 if (!This
->initialized
)
366 return DIERR_NOTINITIALIZED
;
368 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
369 if (!dinput_devices
[i
]->enum_deviceA
) continue;
370 for (j
= 0, r
= -1; r
!= 0; j
++) {
371 devInstance
.dwSize
= sizeof(devInstance
);
372 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
373 if ((r
= dinput_devices
[i
]->enum_deviceA(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
))) {
374 if (lpCallback(&devInstance
,pvRef
) == DIENUM_STOP
)
382 /******************************************************************************
383 * IDirectInputW_EnumDevices
385 static HRESULT WINAPI
IDirectInputWImpl_EnumDevices(
386 LPDIRECTINPUT7W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
387 LPVOID pvRef
, DWORD dwFlags
)
389 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
390 DIDEVICEINSTANCEW devInstance
;
394 TRACE("(this=%p,0x%04x '%s',%p,%p,%04x)\n",
395 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
),
396 lpCallback
, pvRef
, dwFlags
);
397 _dump_EnumDevices_dwFlags(dwFlags
);
400 dwFlags
& ~(DIEDFL_ATTACHEDONLY
| DIEDFL_FORCEFEEDBACK
| DIEDFL_INCLUDEALIASES
| DIEDFL_INCLUDEPHANTOMS
| DIEDFL_INCLUDEHIDDEN
) ||
401 (dwDevType
> DI8DEVCLASS_GAMECTRL
&& dwDevType
< DI8DEVTYPE_DEVICE
) || dwDevType
> DI8DEVTYPE_SUPPLEMENTAL
)
402 return DIERR_INVALIDPARAM
;
404 if (!This
->initialized
)
405 return DIERR_NOTINITIALIZED
;
407 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
408 if (!dinput_devices
[i
]->enum_deviceW
) continue;
409 for (j
= 0, r
= -1; r
!= 0; j
++) {
410 devInstance
.dwSize
= sizeof(devInstance
);
411 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
412 if ((r
= dinput_devices
[i
]->enum_deviceW(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
))) {
413 if (lpCallback(&devInstance
,pvRef
) == DIENUM_STOP
)
422 static ULONG WINAPI
IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface
)
424 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
425 ULONG ref
= InterlockedIncrement(&This
->ref
);
427 TRACE( "(%p) incrementing from %d\n", This
, ref
- 1);
431 static ULONG WINAPI
IDirectInputWImpl_AddRef(LPDIRECTINPUT7W iface
)
433 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
434 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
437 static ULONG WINAPI
IDirectInputAImpl_Release(LPDIRECTINPUT7A iface
)
439 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
440 ULONG ref
= InterlockedDecrement( &This
->ref
);
442 TRACE( "(%p) releasing from %d\n", This
, ref
+ 1 );
446 uninitialize_directinput_instance( This
);
447 HeapFree( GetProcessHeap(), 0, This
);
453 static ULONG WINAPI
IDirectInputWImpl_Release(LPDIRECTINPUT7W iface
)
455 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
456 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
459 static HRESULT WINAPI
IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface
, REFIID riid
, LPVOID
*ppobj
)
461 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
463 TRACE( "(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
468 if (IsEqualGUID( &IID_IUnknown
, riid
) ||
469 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
470 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
471 IsEqualGUID( &IID_IDirectInput7A
, riid
))
473 *ppobj
= &This
->IDirectInput7A_iface
;
474 IUnknown_AddRef( (IUnknown
*)*ppobj
);
479 if (IsEqualGUID( &IID_IDirectInputW
, riid
) ||
480 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
481 IsEqualGUID( &IID_IDirectInput7W
, riid
))
483 *ppobj
= &This
->IDirectInput7W_iface
;
484 IUnknown_AddRef( (IUnknown
*)*ppobj
);
489 if (IsEqualGUID( &IID_IDirectInput8A
, riid
))
491 *ppobj
= &This
->IDirectInput8A_iface
;
492 IUnknown_AddRef( (IUnknown
*)*ppobj
);
497 if (IsEqualGUID( &IID_IDirectInput8W
, riid
))
499 *ppobj
= &This
->IDirectInput8W_iface
;
500 IUnknown_AddRef( (IUnknown
*)*ppobj
);
505 if (IsEqualGUID( &IID_IDirectInputJoyConfig8
, riid
))
507 *ppobj
= &This
->IDirectInputJoyConfig8_iface
;
508 IUnknown_AddRef( (IUnknown
*)*ppobj
);
513 FIXME( "Unsupported interface: %s\n", debugstr_guid(riid
));
515 return E_NOINTERFACE
;
518 static HRESULT WINAPI
IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface
, REFIID riid
, LPVOID
*ppobj
)
520 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
521 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
524 static HRESULT
initialize_directinput_instance(IDirectInputImpl
*This
, DWORD dwVersion
)
526 if (!This
->initialized
)
528 This
->dwVersion
= dwVersion
;
529 This
->evsequence
= 1;
531 InitializeCriticalSection( &This
->crit
);
532 This
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IDirectInputImpl*->crit");
534 list_init( &This
->devices_list
);
536 /* Add self to the list of the IDirectInputs */
537 EnterCriticalSection( &dinput_hook_crit
);
538 list_add_head( &direct_input_list
, &This
->entry
);
539 LeaveCriticalSection( &dinput_hook_crit
);
541 This
->initialized
= TRUE
;
543 if (!check_hook_thread())
545 uninitialize_directinput_instance( This
);
546 return DIERR_GENERIC
;
553 static void uninitialize_directinput_instance(IDirectInputImpl
*This
)
555 if (This
->initialized
)
557 /* Remove self from the list of the IDirectInputs */
558 EnterCriticalSection( &dinput_hook_crit
);
559 list_remove( &This
->entry
);
560 LeaveCriticalSection( &dinput_hook_crit
);
564 This
->crit
.DebugInfo
->Spare
[0] = 0;
565 DeleteCriticalSection( &This
->crit
);
567 This
->initialized
= FALSE
;
571 enum directinput_versions
573 DIRECTINPUT_VERSION_300
= 0x0300,
574 DIRECTINPUT_VERSION_500
= 0x0500,
575 DIRECTINPUT_VERSION_50A
= 0x050A,
576 DIRECTINPUT_VERSION_5B2
= 0x05B2,
577 DIRECTINPUT_VERSION_602
= 0x0602,
578 DIRECTINPUT_VERSION_61A
= 0x061A,
579 DIRECTINPUT_VERSION_700
= 0x0700,
582 static HRESULT WINAPI
IDirectInputAImpl_Initialize(LPDIRECTINPUT7A iface
, HINSTANCE hinst
, DWORD version
)
584 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
586 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
589 return DIERR_INVALIDPARAM
;
590 else if (version
== 0)
591 return DIERR_NOTINITIALIZED
;
592 else if (version
> DIRECTINPUT_VERSION_700
)
593 return DIERR_OLDDIRECTINPUTVERSION
;
594 else if (version
!= DIRECTINPUT_VERSION_300
&& version
!= DIRECTINPUT_VERSION_500
&&
595 version
!= DIRECTINPUT_VERSION_50A
&& version
!= DIRECTINPUT_VERSION_5B2
&&
596 version
!= DIRECTINPUT_VERSION_602
&& version
!= DIRECTINPUT_VERSION_61A
&&
597 version
!= DIRECTINPUT_VERSION_700
&& version
!= DIRECTINPUT_VERSION
)
598 return DIERR_BETADIRECTINPUTVERSION
;
600 return initialize_directinput_instance(This
, version
);
603 static HRESULT WINAPI
IDirectInputWImpl_Initialize(LPDIRECTINPUT7W iface
, HINSTANCE hinst
, DWORD x
)
605 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
606 return IDirectInputAImpl_Initialize( &This
->IDirectInput7A_iface
, hinst
, x
);
609 static HRESULT WINAPI
IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface
, REFGUID rguid
)
611 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
613 LPDIRECTINPUTDEVICEA device
;
615 TRACE( "(%p)->(%s)\n", This
, debugstr_guid(rguid
) );
617 if (!rguid
) return E_POINTER
;
618 if (!This
->initialized
)
619 return DIERR_NOTINITIALIZED
;
621 hr
= IDirectInput_CreateDevice( iface
, rguid
, &device
, NULL
);
622 if (hr
!= DI_OK
) return DI_NOTATTACHED
;
624 IUnknown_Release( device
);
629 static HRESULT WINAPI
IDirectInputWImpl_GetDeviceStatus(LPDIRECTINPUT7W iface
, REFGUID rguid
)
631 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
632 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
635 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface
,
639 WCHAR control_exeW
[] = {'c','o','n','t','r','o','l','.','e','x','e',0};
640 STARTUPINFOW si
= {0};
641 PROCESS_INFORMATION pi
;
643 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
645 TRACE( "(%p)->(%p, %08x)\n", This
, hwndOwner
, dwFlags
);
647 if (hwndOwner
&& !IsWindow(hwndOwner
))
651 return DIERR_INVALIDPARAM
;
653 if (!This
->initialized
)
654 return DIERR_NOTINITIALIZED
;
656 if (!CreateProcessW(NULL
, control_exeW
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
657 return HRESULT_FROM_WIN32(GetLastError());
662 static HRESULT WINAPI
IDirectInputWImpl_RunControlPanel(LPDIRECTINPUT7W iface
, HWND hwndOwner
, DWORD dwFlags
)
664 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
665 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
668 static HRESULT WINAPI
IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
669 LPCSTR pszName
, LPGUID pguidInstance
)
671 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
673 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), pszName
, pguidInstance
);
678 static HRESULT WINAPI
IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
679 LPCWSTR pszName
, LPGUID pguidInstance
)
681 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
683 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), debugstr_w(pszName
), pguidInstance
);
688 static HRESULT
create_device(IDirectInputImpl
*This
, REFGUID rguid
, REFIID riid
, LPVOID
*pvOut
, BOOL unicode
)
695 if (!rguid
|| !pvOut
)
698 if (!This
->initialized
)
699 return DIERR_NOTINITIALIZED
;
701 /* Loop on all the devices to see if anyone matches the given GUID */
702 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
706 if (!dinput_devices
[i
]->create_device
) continue;
707 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, riid
, pvOut
, unicode
)) == DI_OK
)
711 WARN("invalid device GUID %s\n", debugstr_guid(rguid
));
712 return DIERR_DEVICENOTREG
;
715 static HRESULT WINAPI
IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface
, REFGUID rguid
,
716 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
718 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
720 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
722 return create_device(This
, rguid
, riid
, pvOut
, FALSE
);
725 static HRESULT WINAPI
IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface
, REFGUID rguid
,
726 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
728 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
730 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
732 return create_device(This
, rguid
, riid
, pvOut
, TRUE
);
735 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
736 LPDIRECTINPUTDEVICEA
* pdev
, LPUNKNOWN punk
)
738 return IDirectInput7AImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
741 static HRESULT WINAPI
IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
742 LPDIRECTINPUTDEVICEW
* pdev
, LPUNKNOWN punk
)
744 return IDirectInput7WImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
747 /*******************************************************************************
751 static ULONG WINAPI
IDirectInput8AImpl_AddRef(LPDIRECTINPUT8A iface
)
753 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
754 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
757 static ULONG WINAPI
IDirectInput8WImpl_AddRef(LPDIRECTINPUT8W iface
)
759 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
760 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
763 static HRESULT WINAPI
IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface
, REFIID riid
, LPVOID
*ppobj
)
765 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
766 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
769 static HRESULT WINAPI
IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W iface
, REFIID riid
, LPVOID
*ppobj
)
771 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
772 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
775 static ULONG WINAPI
IDirectInput8AImpl_Release(LPDIRECTINPUT8A iface
)
777 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
778 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
781 static ULONG WINAPI
IDirectInput8WImpl_Release(LPDIRECTINPUT8W iface
)
783 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
784 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
787 static HRESULT WINAPI
IDirectInput8AImpl_CreateDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
,
788 LPDIRECTINPUTDEVICE8A
* pdev
, LPUNKNOWN punk
)
790 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
791 return IDirectInput7AImpl_CreateDeviceEx( &This
->IDirectInput7A_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
794 static HRESULT WINAPI
IDirectInput8WImpl_CreateDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
,
795 LPDIRECTINPUTDEVICE8W
* pdev
, LPUNKNOWN punk
)
797 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
798 return IDirectInput7WImpl_CreateDeviceEx( &This
->IDirectInput7W_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
801 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevices(LPDIRECTINPUT8A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
802 LPVOID pvRef
, DWORD dwFlags
)
804 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
805 return IDirectInputAImpl_EnumDevices( &This
->IDirectInput7A_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
808 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
809 LPVOID pvRef
, DWORD dwFlags
)
811 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
812 return IDirectInputWImpl_EnumDevices( &This
->IDirectInput7W_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
815 static HRESULT WINAPI
IDirectInput8AImpl_GetDeviceStatus(LPDIRECTINPUT8A iface
, REFGUID rguid
)
817 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
818 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
821 static HRESULT WINAPI
IDirectInput8WImpl_GetDeviceStatus(LPDIRECTINPUT8W iface
, REFGUID rguid
)
823 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
824 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
827 static HRESULT WINAPI
IDirectInput8AImpl_RunControlPanel(LPDIRECTINPUT8A iface
, HWND hwndOwner
, DWORD dwFlags
)
829 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
830 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
833 static HRESULT WINAPI
IDirectInput8WImpl_RunControlPanel(LPDIRECTINPUT8W iface
, HWND hwndOwner
, DWORD dwFlags
)
835 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
836 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
839 static HRESULT WINAPI
IDirectInput8AImpl_Initialize(LPDIRECTINPUT8A iface
, HINSTANCE hinst
, DWORD version
)
841 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
843 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
846 return DIERR_INVALIDPARAM
;
847 else if (version
== 0)
848 return DIERR_NOTINITIALIZED
;
849 else if (version
< DIRECTINPUT_VERSION
)
850 return DIERR_BETADIRECTINPUTVERSION
;
851 else if (version
> DIRECTINPUT_VERSION
)
852 return DIERR_OLDDIRECTINPUTVERSION
;
854 return initialize_directinput_instance(This
, version
);
857 static HRESULT WINAPI
IDirectInput8WImpl_Initialize(LPDIRECTINPUT8W iface
, HINSTANCE hinst
, DWORD version
)
859 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
860 return IDirectInput8AImpl_Initialize( &This
->IDirectInput8A_iface
, hinst
, version
);
863 static HRESULT WINAPI
IDirectInput8AImpl_FindDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
, LPCSTR pszName
, LPGUID pguidInstance
)
865 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
866 return IDirectInput2AImpl_FindDevice( &This
->IDirectInput7A_iface
, rguid
, pszName
, pguidInstance
);
869 static HRESULT WINAPI
IDirectInput8WImpl_FindDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
, LPCWSTR pszName
, LPGUID pguidInstance
)
871 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
872 return IDirectInput2WImpl_FindDevice( &This
->IDirectInput7W_iface
, rguid
, pszName
, pguidInstance
);
875 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevicesBySemantics(
876 LPDIRECTINPUT8A iface
, LPCSTR ptszUserName
, LPDIACTIONFORMATA lpdiActionFormat
,
877 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback
,
878 LPVOID pvRef
, DWORD dwFlags
881 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
882 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
883 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
884 DIDEVICEINSTANCEA didevi
;
885 LPDIRECTINPUTDEVICE8A lpdid
;
890 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_a(ptszUserName
), lpdiActionFormat
,
891 lpCallback
, pvRef
, dwFlags
);
892 #define X(x) if (dwFlags & x) FIXME("\tdwFlags |= "#x"\n");
893 X(DIEDBSFL_ATTACHEDONLY
)
895 X(DIEDBSFL_FORCEFEEDBACK
)
896 X(DIEDBSFL_AVAILABLEDEVICES
)
897 X(DIEDBSFL_MULTIMICEKEYBOARDS
)
898 X(DIEDBSFL_NONGAMINGDEVICES
)
901 _dump_diactionformatA(lpdiActionFormat
);
903 didevi
.dwSize
= sizeof(didevi
);
905 /* Enumerate all the joysticks */
906 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
910 if (!dinput_devices
[i
]->enum_deviceA
) continue;
912 for (j
= 0, enumSuccess
= -1; enumSuccess
!= 0; j
++)
914 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
916 callbackFlags
= diactionformat_priorityA(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
917 /* Default behavior is to enumerate attached game controllers */
918 enumSuccess
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
921 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
923 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
929 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
931 /* Enumerate keyboard and mouse */
932 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
934 callbackFlags
= diactionformat_priorityA(lpdiActionFormat
, actionMasks
[i
]);
936 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
937 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
939 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
946 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevicesBySemantics(
947 LPDIRECTINPUT8W iface
, LPCWSTR ptszUserName
, LPDIACTIONFORMATW lpdiActionFormat
,
948 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback
,
949 LPVOID pvRef
, DWORD dwFlags
952 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
953 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
954 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
955 DIDEVICEINSTANCEW didevi
;
956 LPDIRECTINPUTDEVICE8W lpdid
;
960 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_w(ptszUserName
), lpdiActionFormat
,
961 lpCallback
, pvRef
, dwFlags
);
963 didevi
.dwSize
= sizeof(didevi
);
965 /* Enumerate all the joysticks */
966 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
970 if (!dinput_devices
[i
]->enum_deviceW
) continue;
972 for (j
= 0, enumSuccess
= -1; enumSuccess
!= 0; j
++)
974 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
976 callbackFlags
= diactionformat_priorityW(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
977 /* Default behavior is to enumerate attached game controllers */
978 enumSuccess
= dinput_devices
[i
]->enum_deviceW(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
981 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
983 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
989 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
991 /* Enumerate keyboard and mouse */
992 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
994 callbackFlags
= diactionformat_priorityW(lpdiActionFormat
, actionMasks
[i
]);
996 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
997 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
999 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
1006 static HRESULT WINAPI
IDirectInput8WImpl_ConfigureDevices(
1007 LPDIRECTINPUT8W iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1008 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1011 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
1013 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1015 /* Call helper function in config.c to do the real work */
1016 return _configure_devices(iface
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1019 static HRESULT WINAPI
IDirectInput8AImpl_ConfigureDevices(
1020 LPDIRECTINPUT8A iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1021 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1024 IDirectInputImpl
*This
= impl_from_IDirectInput8A(iface
);
1025 DIACTIONFORMATW diafW
;
1026 DICONFIGUREDEVICESPARAMSW diCDParamsW
;
1030 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1032 /* Copy parameters */
1033 diCDParamsW
.dwSize
= sizeof(DICONFIGUREDEVICESPARAMSW
);
1034 diCDParamsW
.dwcFormats
= lpdiCDParams
->dwcFormats
;
1035 diCDParamsW
.lprgFormats
= &diafW
;
1036 diCDParamsW
.hwnd
= lpdiCDParams
->hwnd
;
1038 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiCDParams
->lprgFormats
->dwNumActions
);
1039 _copy_diactionformatAtoW(&diafW
, lpdiCDParams
->lprgFormats
);
1041 /* Copy action names */
1042 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1044 const char* from
= lpdiCDParams
->lprgFormats
->rgoAction
[i
].u
.lptszActionName
;
1045 int len
= MultiByteToWideChar(CP_ACP
, 0, from
, -1, NULL
, 0);
1046 WCHAR
*to
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*len
);
1048 MultiByteToWideChar(CP_ACP
, 0, from
, -1, to
, len
);
1049 diafW
.rgoAction
[i
].u
.lptszActionName
= to
;
1052 hr
= IDirectInput8WImpl_ConfigureDevices(&This
->IDirectInput8W_iface
, lpdiCallback
, &diCDParamsW
, dwFlags
, pvRefData
);
1054 /* Copy back configuration */
1056 _copy_diactionformatWtoA(lpdiCDParams
->lprgFormats
, &diafW
);
1059 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1060 HeapFree(GetProcessHeap(), 0, (void*) diafW
.rgoAction
[i
].u
.lptszActionName
);
1062 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
1067 /*****************************************************************************
1068 * IDirectInputJoyConfig8 interface
1071 static inline IDirectInputImpl
*impl_from_IDirectInputJoyConfig8(IDirectInputJoyConfig8
*iface
)
1073 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInputJoyConfig8_iface
);
1076 static HRESULT WINAPI
JoyConfig8Impl_QueryInterface(IDirectInputJoyConfig8
*iface
, REFIID riid
, void** ppobj
)
1078 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1079 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
1082 static ULONG WINAPI
JoyConfig8Impl_AddRef(IDirectInputJoyConfig8
*iface
)
1084 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1085 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
1088 static ULONG WINAPI
JoyConfig8Impl_Release(IDirectInputJoyConfig8
*iface
)
1090 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1091 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
1094 static HRESULT WINAPI
JoyConfig8Impl_Acquire(IDirectInputJoyConfig8
*iface
)
1096 FIXME( "(%p): stub!\n", iface
);
1100 static HRESULT WINAPI
JoyConfig8Impl_Unacquire(IDirectInputJoyConfig8
*iface
)
1102 FIXME( "(%p): stub!\n", iface
);
1106 static HRESULT WINAPI
JoyConfig8Impl_SetCooperativeLevel(IDirectInputJoyConfig8
*iface
, HWND hwnd
, DWORD flags
)
1108 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, hwnd
, flags
);
1112 static HRESULT WINAPI
JoyConfig8Impl_SendNotify(IDirectInputJoyConfig8
*iface
)
1114 FIXME( "(%p): stub!\n", iface
);
1118 static HRESULT WINAPI
JoyConfig8Impl_EnumTypes(IDirectInputJoyConfig8
*iface
, LPDIJOYTYPECALLBACK cb
, void *ref
)
1120 FIXME( "(%p)->(%p, %p): stub!\n", iface
, cb
, ref
);
1124 static HRESULT WINAPI
JoyConfig8Impl_GetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPDIJOYTYPEINFO info
, DWORD flags
)
1126 FIXME( "(%p)->(%s, %p, 0x%08x): stub!\n", iface
, debugstr_w(name
), info
, flags
);
1130 static HRESULT WINAPI
JoyConfig8Impl_SetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPCDIJOYTYPEINFO info
, DWORD flags
,
1133 FIXME( "(%p)->(%s, %p, 0x%08x, %s): stub!\n", iface
, debugstr_w(name
), info
, flags
, debugstr_w(new_name
) );
1137 static HRESULT WINAPI
JoyConfig8Impl_DeleteType(IDirectInputJoyConfig8
*iface
, LPCWSTR name
)
1139 FIXME( "(%p)->(%s): stub!\n", iface
, debugstr_w(name
) );
1143 static HRESULT WINAPI
JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPDIJOYCONFIG info
, DWORD flags
)
1145 IDirectInputImpl
*di
= impl_from_IDirectInputJoyConfig8(iface
);
1149 FIXME("(%p)->(%d, %p, 0x%08x): semi-stub!\n", iface
, id
, info
, flags
);
1151 #define X(x) if (flags & x) FIXME("\tflags |= "#x"\n");
1152 X(DIJC_GUIDINSTANCE
)
1153 X(DIJC_REGHWCONFIGTYPE
)
1158 /* Enumerate all joysticks in order */
1159 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
1161 if (!dinput_devices
[i
]->enum_deviceA
) continue;
1163 for (j
= 0, r
= -1; r
!= 0; j
++)
1165 DIDEVICEINSTANCEA dev
;
1166 dev
.dwSize
= sizeof(dev
);
1167 if ((r
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, 0, &dev
, di
->dwVersion
, j
)))
1169 /* Only take into account the chosen id */
1172 if (flags
& DIJC_GUIDINSTANCE
)
1173 info
->guidInstance
= dev
.guidInstance
;
1182 return DIERR_NOMOREITEMS
;
1185 static HRESULT WINAPI
JoyConfig8Impl_SetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPCDIJOYCONFIG info
, DWORD flags
)
1187 FIXME( "(%p)->(%d, %p, 0x%08x): stub!\n", iface
, id
, info
, flags
);
1191 static HRESULT WINAPI
JoyConfig8Impl_DeleteConfig(IDirectInputJoyConfig8
*iface
, UINT id
)
1193 FIXME( "(%p)->(%d): stub!\n", iface
, id
);
1197 static HRESULT WINAPI
JoyConfig8Impl_GetUserValues(IDirectInputJoyConfig8
*iface
, LPDIJOYUSERVALUES info
, DWORD flags
)
1199 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1203 static HRESULT WINAPI
JoyConfig8Impl_SetUserValues(IDirectInputJoyConfig8
*iface
, LPCDIJOYUSERVALUES info
, DWORD flags
)
1205 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1209 static HRESULT WINAPI
JoyConfig8Impl_AddNewHardware(IDirectInputJoyConfig8
*iface
, HWND hwnd
, REFGUID guid
)
1211 FIXME( "(%p)->(%p, %s): stub!\n", iface
, hwnd
, debugstr_guid(guid
) );
1215 static HRESULT WINAPI
JoyConfig8Impl_OpenTypeKey(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, DWORD security
, PHKEY key
)
1217 FIXME( "(%p)->(%s, 0x%08x, %p): stub!\n", iface
, debugstr_w(name
), security
, key
);
1221 static HRESULT WINAPI
JoyConfig8Impl_OpenAppStatusKey(IDirectInputJoyConfig8
*iface
, PHKEY key
)
1223 FIXME( "(%p)->(%p): stub!\n", iface
, key
);
1227 static const IDirectInput7AVtbl ddi7avt
= {
1228 IDirectInputAImpl_QueryInterface
,
1229 IDirectInputAImpl_AddRef
,
1230 IDirectInputAImpl_Release
,
1231 IDirectInputAImpl_CreateDevice
,
1232 IDirectInputAImpl_EnumDevices
,
1233 IDirectInputAImpl_GetDeviceStatus
,
1234 IDirectInputAImpl_RunControlPanel
,
1235 IDirectInputAImpl_Initialize
,
1236 IDirectInput2AImpl_FindDevice
,
1237 IDirectInput7AImpl_CreateDeviceEx
1240 static const IDirectInput7WVtbl ddi7wvt
= {
1241 IDirectInputWImpl_QueryInterface
,
1242 IDirectInputWImpl_AddRef
,
1243 IDirectInputWImpl_Release
,
1244 IDirectInputWImpl_CreateDevice
,
1245 IDirectInputWImpl_EnumDevices
,
1246 IDirectInputWImpl_GetDeviceStatus
,
1247 IDirectInputWImpl_RunControlPanel
,
1248 IDirectInputWImpl_Initialize
,
1249 IDirectInput2WImpl_FindDevice
,
1250 IDirectInput7WImpl_CreateDeviceEx
1253 static const IDirectInput8AVtbl ddi8avt
= {
1254 IDirectInput8AImpl_QueryInterface
,
1255 IDirectInput8AImpl_AddRef
,
1256 IDirectInput8AImpl_Release
,
1257 IDirectInput8AImpl_CreateDevice
,
1258 IDirectInput8AImpl_EnumDevices
,
1259 IDirectInput8AImpl_GetDeviceStatus
,
1260 IDirectInput8AImpl_RunControlPanel
,
1261 IDirectInput8AImpl_Initialize
,
1262 IDirectInput8AImpl_FindDevice
,
1263 IDirectInput8AImpl_EnumDevicesBySemantics
,
1264 IDirectInput8AImpl_ConfigureDevices
1267 static const IDirectInput8WVtbl ddi8wvt
= {
1268 IDirectInput8WImpl_QueryInterface
,
1269 IDirectInput8WImpl_AddRef
,
1270 IDirectInput8WImpl_Release
,
1271 IDirectInput8WImpl_CreateDevice
,
1272 IDirectInput8WImpl_EnumDevices
,
1273 IDirectInput8WImpl_GetDeviceStatus
,
1274 IDirectInput8WImpl_RunControlPanel
,
1275 IDirectInput8WImpl_Initialize
,
1276 IDirectInput8WImpl_FindDevice
,
1277 IDirectInput8WImpl_EnumDevicesBySemantics
,
1278 IDirectInput8WImpl_ConfigureDevices
1281 static const IDirectInputJoyConfig8Vtbl JoyConfig8vt
=
1283 JoyConfig8Impl_QueryInterface
,
1284 JoyConfig8Impl_AddRef
,
1285 JoyConfig8Impl_Release
,
1286 JoyConfig8Impl_Acquire
,
1287 JoyConfig8Impl_Unacquire
,
1288 JoyConfig8Impl_SetCooperativeLevel
,
1289 JoyConfig8Impl_SendNotify
,
1290 JoyConfig8Impl_EnumTypes
,
1291 JoyConfig8Impl_GetTypeInfo
,
1292 JoyConfig8Impl_SetTypeInfo
,
1293 JoyConfig8Impl_DeleteType
,
1294 JoyConfig8Impl_GetConfig
,
1295 JoyConfig8Impl_SetConfig
,
1296 JoyConfig8Impl_DeleteConfig
,
1297 JoyConfig8Impl_GetUserValues
,
1298 JoyConfig8Impl_SetUserValues
,
1299 JoyConfig8Impl_AddNewHardware
,
1300 JoyConfig8Impl_OpenTypeKey
,
1301 JoyConfig8Impl_OpenAppStatusKey
1304 /*******************************************************************************
1305 * DirectInput ClassFactory
1309 /* IUnknown fields */
1310 IClassFactory IClassFactory_iface
;
1312 } IClassFactoryImpl
;
1314 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
1316 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
1319 static HRESULT WINAPI
DICF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
1320 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1322 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
1323 return E_NOINTERFACE
;
1326 static ULONG WINAPI
DICF_AddRef(LPCLASSFACTORY iface
) {
1327 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1328 return InterlockedIncrement(&(This
->ref
));
1331 static ULONG WINAPI
DICF_Release(LPCLASSFACTORY iface
) {
1332 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1333 /* static class, won't be freed */
1334 return InterlockedDecrement(&(This
->ref
));
1337 static HRESULT WINAPI
DICF_CreateInstance(
1338 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
1340 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1342 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1343 if ( IsEqualGUID( &IID_IUnknown
, riid
) ||
1344 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
1345 IsEqualGUID( &IID_IDirectInputW
, riid
) ||
1346 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
1347 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
1348 IsEqualGUID( &IID_IDirectInput7A
, riid
) ||
1349 IsEqualGUID( &IID_IDirectInput7W
, riid
) ) {
1350 return create_directinput_instance(riid
, ppobj
, NULL
);
1353 FIXME("(%p,%p,%s,%p) Interface not found!\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1354 return E_NOINTERFACE
;
1357 static HRESULT WINAPI
DICF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
1358 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1359 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
1363 static const IClassFactoryVtbl DICF_Vtbl
= {
1364 DICF_QueryInterface
,
1367 DICF_CreateInstance
,
1370 static IClassFactoryImpl DINPUT_CF
= {{&DICF_Vtbl
}, 1 };
1372 /***********************************************************************
1373 * DllCanUnloadNow (DINPUT.@)
1375 HRESULT WINAPI
DllCanUnloadNow(void)
1380 /***********************************************************************
1381 * DllGetClassObject (DINPUT.@)
1383 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1385 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1386 if ( IsEqualCLSID( &IID_IClassFactory
, riid
) ) {
1388 IClassFactory_AddRef((IClassFactory
*)*ppv
);
1392 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1393 return CLASS_E_CLASSNOTAVAILABLE
;
1396 /***********************************************************************
1397 * DllRegisterServer (DINPUT.@)
1399 HRESULT WINAPI
DllRegisterServer(void)
1401 return __wine_register_resources( DINPUT_instance
);
1404 /***********************************************************************
1405 * DllUnregisterServer (DINPUT.@)
1407 HRESULT WINAPI
DllUnregisterServer(void)
1409 return __wine_unregister_resources( DINPUT_instance
);
1412 /******************************************************************************
1413 * DInput hook thread
1416 static LRESULT CALLBACK
LL_hook_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1418 IDirectInputImpl
*dinput
;
1421 if (code
!= HC_ACTION
) return CallNextHookEx( 0, code
, wparam
, lparam
);
1423 EnterCriticalSection( &dinput_hook_crit
);
1424 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1426 IDirectInputDeviceImpl
*dev
;
1428 EnterCriticalSection( &dinput
->crit
);
1429 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1430 if (dev
->acquired
&& dev
->event_proc
)
1432 TRACE("calling %p->%p (%lx %lx)\n", dev
, dev
->event_proc
, wparam
, lparam
);
1433 skip
|= dev
->event_proc( &dev
->IDirectInputDevice8A_iface
, wparam
, lparam
);
1435 LeaveCriticalSection( &dinput
->crit
);
1437 LeaveCriticalSection( &dinput_hook_crit
);
1439 return skip
? 1 : CallNextHookEx( 0, code
, wparam
, lparam
);
1442 static LRESULT CALLBACK
callwndproc_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1444 CWPSTRUCT
*msg
= (CWPSTRUCT
*)lparam
;
1445 IDirectInputImpl
*dinput
;
1448 if (code
!= HC_ACTION
|| (msg
->message
!= WM_KILLFOCUS
&&
1449 msg
->message
!= WM_ACTIVATEAPP
&& msg
->message
!= WM_ACTIVATE
))
1450 return CallNextHookEx( 0, code
, wparam
, lparam
);
1452 foreground
= GetForegroundWindow();
1454 EnterCriticalSection( &dinput_hook_crit
);
1456 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1458 IDirectInputDeviceImpl
*dev
;
1460 EnterCriticalSection( &dinput
->crit
);
1461 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1463 if (!dev
->acquired
) continue;
1465 if (msg
->hwnd
== dev
->win
&& msg
->hwnd
!= foreground
)
1467 TRACE( "%p window is not foreground - unacquiring %p\n", dev
->win
, dev
);
1468 IDirectInputDevice_Unacquire( &dev
->IDirectInputDevice8A_iface
);
1471 LeaveCriticalSection( &dinput
->crit
);
1473 LeaveCriticalSection( &dinput_hook_crit
);
1475 return CallNextHookEx( 0, code
, wparam
, lparam
);
1478 static DWORD WINAPI
hook_thread_proc(void *param
)
1480 static HHOOK kbd_hook
, mouse_hook
;
1483 /* Force creation of the message queue */
1484 PeekMessageW( &msg
, 0, 0, 0, PM_NOREMOVE
);
1485 SetEvent(*(LPHANDLE
)param
);
1487 while (GetMessageW( &msg
, 0, 0, 0 ))
1489 UINT kbd_cnt
= 0, mice_cnt
= 0;
1491 if (msg
.message
== WM_USER
+0x10)
1493 IDirectInputImpl
*dinput
;
1495 TRACE( "Processing hook change notification lp:%ld\n", msg
.lParam
);
1497 if (!msg
.wParam
&& !msg
.lParam
)
1499 if (kbd_hook
) UnhookWindowsHookEx( kbd_hook
);
1500 if (mouse_hook
) UnhookWindowsHookEx( mouse_hook
);
1501 kbd_hook
= mouse_hook
= NULL
;
1505 EnterCriticalSection( &dinput_hook_crit
);
1507 /* Count acquired keyboards and mice*/
1508 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1510 IDirectInputDeviceImpl
*dev
;
1512 EnterCriticalSection( &dinput
->crit
);
1513 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1515 if (!dev
->acquired
|| !dev
->event_proc
) continue;
1517 if (IsEqualGUID( &dev
->guid
, &GUID_SysKeyboard
) ||
1518 IsEqualGUID( &dev
->guid
, &DInput_Wine_Keyboard_GUID
))
1521 if (IsEqualGUID( &dev
->guid
, &GUID_SysMouse
) ||
1522 IsEqualGUID( &dev
->guid
, &DInput_Wine_Mouse_GUID
))
1525 LeaveCriticalSection( &dinput
->crit
);
1527 LeaveCriticalSection( &dinput_hook_crit
);
1529 if (kbd_cnt
&& !kbd_hook
)
1530 kbd_hook
= SetWindowsHookExW( WH_KEYBOARD_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1531 else if (!kbd_cnt
&& kbd_hook
)
1533 UnhookWindowsHookEx( kbd_hook
);
1537 if (mice_cnt
&& !mouse_hook
)
1538 mouse_hook
= SetWindowsHookExW( WH_MOUSE_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1539 else if (!mice_cnt
&& mouse_hook
)
1541 UnhookWindowsHookEx( mouse_hook
);
1545 TranslateMessage(&msg
);
1546 DispatchMessageW(&msg
);
1552 static DWORD hook_thread_id
;
1554 static CRITICAL_SECTION_DEBUG dinput_critsect_debug
=
1556 0, 0, &dinput_hook_crit
,
1557 { &dinput_critsect_debug
.ProcessLocksList
, &dinput_critsect_debug
.ProcessLocksList
},
1558 0, 0, { (DWORD_PTR
)(__FILE__
": dinput_hook_crit") }
1560 static CRITICAL_SECTION dinput_hook_crit
= { &dinput_critsect_debug
, -1, 0, 0, 0, 0 };
1562 static BOOL
check_hook_thread(void)
1564 static HANDLE hook_thread
;
1566 EnterCriticalSection(&dinput_hook_crit
);
1568 TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list
));
1569 if (!list_empty(&direct_input_list
) && !hook_thread
)
1573 event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1574 hook_thread
= CreateThread(NULL
, 0, hook_thread_proc
, &event
, 0, &hook_thread_id
);
1575 if (event
&& hook_thread
)
1579 handles
[1] = hook_thread
;
1580 WaitForMultipleObjects(2, handles
, FALSE
, INFINITE
);
1582 LeaveCriticalSection(&dinput_hook_crit
);
1585 else if (list_empty(&direct_input_list
) && hook_thread
)
1587 DWORD tid
= hook_thread_id
;
1590 PostThreadMessageW(tid
, WM_USER
+0x10, 0, 0);
1591 LeaveCriticalSection(&dinput_hook_crit
);
1593 /* wait for hook thread to exit */
1594 WaitForSingleObject(hook_thread
, INFINITE
);
1595 CloseHandle(hook_thread
);
1599 LeaveCriticalSection(&dinput_hook_crit
);
1601 return hook_thread_id
!= 0;
1604 void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface
)
1606 static HHOOK callwndproc_hook
;
1607 static ULONG foreground_cnt
;
1608 IDirectInputDeviceImpl
*dev
= impl_from_IDirectInputDevice8W(iface
);
1610 EnterCriticalSection(&dinput_hook_crit
);
1612 if (dev
->dwCoopLevel
& DISCL_FOREGROUND
)
1620 if (foreground_cnt
&& !callwndproc_hook
)
1621 callwndproc_hook
= SetWindowsHookExW( WH_CALLWNDPROC
, callwndproc_proc
,
1622 DINPUT_instance
, GetCurrentThreadId() );
1623 else if (!foreground_cnt
&& callwndproc_hook
)
1625 UnhookWindowsHookEx( callwndproc_hook
);
1626 callwndproc_hook
= NULL
;
1629 PostThreadMessageW( hook_thread_id
, WM_USER
+0x10, 1, 0 );
1631 LeaveCriticalSection(&dinput_hook_crit
);
1634 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserv
)
1638 case DLL_PROCESS_ATTACH
:
1639 DisableThreadLibraryCalls(inst
);
1640 DINPUT_instance
= inst
;
1642 case DLL_PROCESS_DETACH
:
1643 DeleteCriticalSection(&dinput_hook_crit
);