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
->dwActionSize
; 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
->dwActionSize
; 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
) ||
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
) ||
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 (!This
->initialized
)
618 return DIERR_NOTINITIALIZED
;
620 hr
= IDirectInput_CreateDevice( iface
, rguid
, &device
, NULL
);
621 if (hr
!= DI_OK
) return DI_NOTATTACHED
;
623 IUnknown_Release( device
);
628 static HRESULT WINAPI
IDirectInputWImpl_GetDeviceStatus(LPDIRECTINPUT7W iface
, REFGUID rguid
)
630 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
631 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
634 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface
,
638 WCHAR control_exeW
[] = {'c','o','n','t','r','o','l','.','e','x','e',0};
639 STARTUPINFOW si
= {0};
640 PROCESS_INFORMATION pi
;
642 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
644 TRACE( "(%p)->(%p, %08x)\n", This
, hwndOwner
, dwFlags
);
646 if (hwndOwner
&& !IsWindow(hwndOwner
))
650 return DIERR_INVALIDPARAM
;
652 if (!This
->initialized
)
653 return DIERR_NOTINITIALIZED
;
655 if (!CreateProcessW(NULL
, control_exeW
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
656 return HRESULT_FROM_WIN32(GetLastError());
661 static HRESULT WINAPI
IDirectInputWImpl_RunControlPanel(LPDIRECTINPUT7W iface
, HWND hwndOwner
, DWORD dwFlags
)
663 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
664 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
667 static HRESULT WINAPI
IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
668 LPCSTR pszName
, LPGUID pguidInstance
)
670 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
672 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), pszName
, pguidInstance
);
677 static HRESULT WINAPI
IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
678 LPCWSTR pszName
, LPGUID pguidInstance
)
680 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
682 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), debugstr_w(pszName
), pguidInstance
);
687 static HRESULT
create_device(IDirectInputImpl
*This
, REFGUID rguid
, REFIID riid
, LPVOID
*pvOut
, BOOL unicode
)
694 if (!rguid
|| !pvOut
)
697 if (!This
->initialized
)
698 return DIERR_NOTINITIALIZED
;
700 /* Loop on all the devices to see if anyone matches the given GUID */
701 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
705 if (!dinput_devices
[i
]->create_device
) continue;
706 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, riid
, pvOut
, unicode
)) == DI_OK
)
710 WARN("invalid device GUID %s\n", debugstr_guid(rguid
));
711 return DIERR_DEVICENOTREG
;
714 static HRESULT WINAPI
IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface
, REFGUID rguid
,
715 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
717 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
719 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
721 return create_device(This
, rguid
, riid
, pvOut
, FALSE
);
724 static HRESULT WINAPI
IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface
, REFGUID rguid
,
725 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
727 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
729 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
731 return create_device(This
, rguid
, riid
, pvOut
, TRUE
);
734 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
735 LPDIRECTINPUTDEVICEA
* pdev
, LPUNKNOWN punk
)
737 return IDirectInput7AImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
740 static HRESULT WINAPI
IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
741 LPDIRECTINPUTDEVICEW
* pdev
, LPUNKNOWN punk
)
743 return IDirectInput7WImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
746 /*******************************************************************************
750 static ULONG WINAPI
IDirectInput8AImpl_AddRef(LPDIRECTINPUT8A iface
)
752 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
753 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
756 static ULONG WINAPI
IDirectInput8WImpl_AddRef(LPDIRECTINPUT8W iface
)
758 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
759 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
762 static HRESULT WINAPI
IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface
, REFIID riid
, LPVOID
*ppobj
)
764 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
765 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
768 static HRESULT WINAPI
IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W iface
, REFIID riid
, LPVOID
*ppobj
)
770 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
771 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
774 static ULONG WINAPI
IDirectInput8AImpl_Release(LPDIRECTINPUT8A iface
)
776 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
777 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
780 static ULONG WINAPI
IDirectInput8WImpl_Release(LPDIRECTINPUT8W iface
)
782 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
783 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
786 static HRESULT WINAPI
IDirectInput8AImpl_CreateDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
,
787 LPDIRECTINPUTDEVICE8A
* pdev
, LPUNKNOWN punk
)
789 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
790 return IDirectInput7AImpl_CreateDeviceEx( &This
->IDirectInput7A_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
793 static HRESULT WINAPI
IDirectInput8WImpl_CreateDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
,
794 LPDIRECTINPUTDEVICE8W
* pdev
, LPUNKNOWN punk
)
796 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
797 return IDirectInput7WImpl_CreateDeviceEx( &This
->IDirectInput7W_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
800 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevices(LPDIRECTINPUT8A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
801 LPVOID pvRef
, DWORD dwFlags
)
803 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
804 return IDirectInputAImpl_EnumDevices( &This
->IDirectInput7A_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
807 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
808 LPVOID pvRef
, DWORD dwFlags
)
810 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
811 return IDirectInputWImpl_EnumDevices( &This
->IDirectInput7W_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
814 static HRESULT WINAPI
IDirectInput8AImpl_GetDeviceStatus(LPDIRECTINPUT8A iface
, REFGUID rguid
)
816 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
817 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
820 static HRESULT WINAPI
IDirectInput8WImpl_GetDeviceStatus(LPDIRECTINPUT8W iface
, REFGUID rguid
)
822 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
823 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
826 static HRESULT WINAPI
IDirectInput8AImpl_RunControlPanel(LPDIRECTINPUT8A iface
, HWND hwndOwner
, DWORD dwFlags
)
828 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
829 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
832 static HRESULT WINAPI
IDirectInput8WImpl_RunControlPanel(LPDIRECTINPUT8W iface
, HWND hwndOwner
, DWORD dwFlags
)
834 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
835 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
838 static HRESULT WINAPI
IDirectInput8AImpl_Initialize(LPDIRECTINPUT8A iface
, HINSTANCE hinst
, DWORD version
)
840 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
842 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
845 return DIERR_INVALIDPARAM
;
846 else if (version
== 0)
847 return DIERR_NOTINITIALIZED
;
848 else if (version
< DIRECTINPUT_VERSION
)
849 return DIERR_BETADIRECTINPUTVERSION
;
850 else if (version
> DIRECTINPUT_VERSION
)
851 return DIERR_OLDDIRECTINPUTVERSION
;
853 return initialize_directinput_instance(This
, version
);
856 static HRESULT WINAPI
IDirectInput8WImpl_Initialize(LPDIRECTINPUT8W iface
, HINSTANCE hinst
, DWORD version
)
858 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
859 return IDirectInput8AImpl_Initialize( &This
->IDirectInput8A_iface
, hinst
, version
);
862 static HRESULT WINAPI
IDirectInput8AImpl_FindDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
, LPCSTR pszName
, LPGUID pguidInstance
)
864 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
865 return IDirectInput2AImpl_FindDevice( &This
->IDirectInput7A_iface
, rguid
, pszName
, pguidInstance
);
868 static HRESULT WINAPI
IDirectInput8WImpl_FindDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
, LPCWSTR pszName
, LPGUID pguidInstance
)
870 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
871 return IDirectInput2WImpl_FindDevice( &This
->IDirectInput7W_iface
, rguid
, pszName
, pguidInstance
);
874 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevicesBySemantics(
875 LPDIRECTINPUT8A iface
, LPCSTR ptszUserName
, LPDIACTIONFORMATA lpdiActionFormat
,
876 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback
,
877 LPVOID pvRef
, DWORD dwFlags
880 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
881 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
882 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
883 DIDEVICEINSTANCEA didevi
;
884 LPDIRECTINPUTDEVICE8A lpdid
;
889 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_a(ptszUserName
), lpdiActionFormat
,
890 lpCallback
, pvRef
, dwFlags
);
891 #define X(x) if (dwFlags & x) FIXME("\tdwFlags |= "#x"\n");
892 X(DIEDBSFL_ATTACHEDONLY
)
894 X(DIEDBSFL_FORCEFEEDBACK
)
895 X(DIEDBSFL_AVAILABLEDEVICES
)
896 X(DIEDBSFL_MULTIMICEKEYBOARDS
)
897 X(DIEDBSFL_NONGAMINGDEVICES
)
900 _dump_diactionformatA(lpdiActionFormat
);
902 didevi
.dwSize
= sizeof(didevi
);
904 /* Enumerate all the joysticks */
905 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
909 if (!dinput_devices
[i
]->enum_deviceA
) continue;
911 for (j
= 0, enumSuccess
= -1; enumSuccess
!= 0; j
++)
913 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
915 callbackFlags
= _diactionformat_priorityA(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
916 /* Default behavior is to enumerate attached game controllers */
917 enumSuccess
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
920 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
922 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
928 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
930 /* Enumerate keyboard and mouse */
931 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
933 callbackFlags
= _diactionformat_priorityA(lpdiActionFormat
, actionMasks
[i
]);
935 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
936 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
938 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
945 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevicesBySemantics(
946 LPDIRECTINPUT8W iface
, LPCWSTR ptszUserName
, LPDIACTIONFORMATW lpdiActionFormat
,
947 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback
,
948 LPVOID pvRef
, DWORD dwFlags
951 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
952 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
953 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
954 DIDEVICEINSTANCEW didevi
;
955 LPDIRECTINPUTDEVICE8W lpdid
;
959 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_w(ptszUserName
), lpdiActionFormat
,
960 lpCallback
, pvRef
, dwFlags
);
962 didevi
.dwSize
= sizeof(didevi
);
964 /* Enumerate all the joysticks */
965 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
969 if (!dinput_devices
[i
]->enum_deviceW
) continue;
971 for (j
= 0, enumSuccess
= -1; enumSuccess
!= 0; j
++)
973 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
975 callbackFlags
= _diactionformat_priorityW(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
976 /* Default behavior is to enumerate attached game controllers */
977 enumSuccess
= dinput_devices
[i
]->enum_deviceW(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
980 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
982 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
988 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
990 /* Enumerate keyboard and mouse */
991 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
993 callbackFlags
= _diactionformat_priorityW(lpdiActionFormat
, actionMasks
[i
]);
995 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
996 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
998 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
1005 static HRESULT WINAPI
IDirectInput8WImpl_ConfigureDevices(
1006 LPDIRECTINPUT8W iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1007 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1010 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
1012 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1014 /* Call helper function in config.c to do the real work */
1015 return _configure_devices(iface
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1018 static HRESULT WINAPI
IDirectInput8AImpl_ConfigureDevices(
1019 LPDIRECTINPUT8A iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1020 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1023 IDirectInputImpl
*This
= impl_from_IDirectInput8A(iface
);
1024 DIACTIONFORMATW diafW
;
1025 DICONFIGUREDEVICESPARAMSW diCDParamsW
;
1029 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1031 /* Copy parameters */
1032 diCDParamsW
.dwSize
= sizeof(DICONFIGUREDEVICESPARAMSW
);
1033 diCDParamsW
.dwcFormats
= lpdiCDParams
->dwcFormats
;
1034 diCDParamsW
.lprgFormats
= &diafW
;
1035 diCDParamsW
.hwnd
= lpdiCDParams
->hwnd
;
1037 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiCDParams
->lprgFormats
->dwNumActions
);
1038 _copy_diactionformatAtoW(&diafW
, lpdiCDParams
->lprgFormats
);
1040 /* Copy action names */
1041 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1043 const char* from
= lpdiCDParams
->lprgFormats
->rgoAction
[i
].u
.lptszActionName
;
1044 int len
= MultiByteToWideChar(CP_ACP
, 0, from
, -1, NULL
, 0);
1045 WCHAR
*to
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*len
);
1047 MultiByteToWideChar(CP_ACP
, 0, from
, -1, to
, len
);
1048 diafW
.rgoAction
[i
].u
.lptszActionName
= to
;
1051 hr
= IDirectInput8WImpl_ConfigureDevices(&This
->IDirectInput8W_iface
, lpdiCallback
, &diCDParamsW
, dwFlags
, pvRefData
);
1053 /* Copy back configuration */
1055 _copy_diactionformatWtoA(lpdiCDParams
->lprgFormats
, &diafW
);
1058 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1059 HeapFree(GetProcessHeap(), 0, (void*) diafW
.rgoAction
[i
].u
.lptszActionName
);
1061 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
1066 /*****************************************************************************
1067 * IDirectInputJoyConfig8 interface
1070 static inline IDirectInputImpl
*impl_from_IDirectInputJoyConfig8(IDirectInputJoyConfig8
*iface
)
1072 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInputJoyConfig8_iface
);
1075 static HRESULT WINAPI
JoyConfig8Impl_QueryInterface(IDirectInputJoyConfig8
*iface
, REFIID riid
, void** ppobj
)
1077 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1078 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
1081 static ULONG WINAPI
JoyConfig8Impl_AddRef(IDirectInputJoyConfig8
*iface
)
1083 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1084 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
1087 static ULONG WINAPI
JoyConfig8Impl_Release(IDirectInputJoyConfig8
*iface
)
1089 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1090 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
1093 static HRESULT WINAPI
JoyConfig8Impl_Acquire(IDirectInputJoyConfig8
*iface
)
1095 FIXME( "(%p): stub!\n", iface
);
1099 static HRESULT WINAPI
JoyConfig8Impl_Unacquire(IDirectInputJoyConfig8
*iface
)
1101 FIXME( "(%p): stub!\n", iface
);
1105 static HRESULT WINAPI
JoyConfig8Impl_SetCooperativeLevel(IDirectInputJoyConfig8
*iface
, HWND hwnd
, DWORD flags
)
1107 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, hwnd
, flags
);
1111 static HRESULT WINAPI
JoyConfig8Impl_SendNotify(IDirectInputJoyConfig8
*iface
)
1113 FIXME( "(%p): stub!\n", iface
);
1117 static HRESULT WINAPI
JoyConfig8Impl_EnumTypes(IDirectInputJoyConfig8
*iface
, LPDIJOYTYPECALLBACK cb
, void *ref
)
1119 FIXME( "(%p)->(%p, %p): stub!\n", iface
, cb
, ref
);
1123 static HRESULT WINAPI
JoyConfig8Impl_GetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPDIJOYTYPEINFO info
, DWORD flags
)
1125 FIXME( "(%p)->(%s, %p, 0x%08x): stub!\n", iface
, debugstr_w(name
), info
, flags
);
1129 static HRESULT WINAPI
JoyConfig8Impl_SetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPCDIJOYTYPEINFO info
, DWORD flags
,
1132 FIXME( "(%p)->(%s, %p, 0x%08x, %s): stub!\n", iface
, debugstr_w(name
), info
, flags
, debugstr_w(new_name
) );
1136 static HRESULT WINAPI
JoyConfig8Impl_DeleteType(IDirectInputJoyConfig8
*iface
, LPCWSTR name
)
1138 FIXME( "(%p)->(%s): stub!\n", iface
, debugstr_w(name
) );
1142 static HRESULT WINAPI
JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPDIJOYCONFIG info
, DWORD flags
)
1144 FIXME( "(%p)->(%d, %p, 0x%08x): stub!\n", iface
, id
, info
, flags
);
1148 static HRESULT WINAPI
JoyConfig8Impl_SetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPCDIJOYCONFIG info
, DWORD flags
)
1150 FIXME( "(%p)->(%d, %p, 0x%08x): stub!\n", iface
, id
, info
, flags
);
1154 static HRESULT WINAPI
JoyConfig8Impl_DeleteConfig(IDirectInputJoyConfig8
*iface
, UINT id
)
1156 FIXME( "(%p)->(%d): stub!\n", iface
, id
);
1160 static HRESULT WINAPI
JoyConfig8Impl_GetUserValues(IDirectInputJoyConfig8
*iface
, LPDIJOYUSERVALUES info
, DWORD flags
)
1162 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1166 static HRESULT WINAPI
JoyConfig8Impl_SetUserValues(IDirectInputJoyConfig8
*iface
, LPCDIJOYUSERVALUES info
, DWORD flags
)
1168 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1172 static HRESULT WINAPI
JoyConfig8Impl_AddNewHardware(IDirectInputJoyConfig8
*iface
, HWND hwnd
, REFGUID guid
)
1174 FIXME( "(%p)->(%p, %s): stub!\n", iface
, hwnd
, debugstr_guid(guid
) );
1178 static HRESULT WINAPI
JoyConfig8Impl_OpenTypeKey(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, DWORD security
, PHKEY key
)
1180 FIXME( "(%p)->(%s, 0x%08x, %p): stub!\n", iface
, debugstr_w(name
), security
, key
);
1184 static HRESULT WINAPI
JoyConfig8Impl_OpenAppStatusKey(IDirectInputJoyConfig8
*iface
, PHKEY key
)
1186 FIXME( "(%p)->(%p): stub!\n", iface
, key
);
1190 static const IDirectInput7AVtbl ddi7avt
= {
1191 IDirectInputAImpl_QueryInterface
,
1192 IDirectInputAImpl_AddRef
,
1193 IDirectInputAImpl_Release
,
1194 IDirectInputAImpl_CreateDevice
,
1195 IDirectInputAImpl_EnumDevices
,
1196 IDirectInputAImpl_GetDeviceStatus
,
1197 IDirectInputAImpl_RunControlPanel
,
1198 IDirectInputAImpl_Initialize
,
1199 IDirectInput2AImpl_FindDevice
,
1200 IDirectInput7AImpl_CreateDeviceEx
1203 static const IDirectInput7WVtbl ddi7wvt
= {
1204 IDirectInputWImpl_QueryInterface
,
1205 IDirectInputWImpl_AddRef
,
1206 IDirectInputWImpl_Release
,
1207 IDirectInputWImpl_CreateDevice
,
1208 IDirectInputWImpl_EnumDevices
,
1209 IDirectInputWImpl_GetDeviceStatus
,
1210 IDirectInputWImpl_RunControlPanel
,
1211 IDirectInputWImpl_Initialize
,
1212 IDirectInput2WImpl_FindDevice
,
1213 IDirectInput7WImpl_CreateDeviceEx
1216 static const IDirectInput8AVtbl ddi8avt
= {
1217 IDirectInput8AImpl_QueryInterface
,
1218 IDirectInput8AImpl_AddRef
,
1219 IDirectInput8AImpl_Release
,
1220 IDirectInput8AImpl_CreateDevice
,
1221 IDirectInput8AImpl_EnumDevices
,
1222 IDirectInput8AImpl_GetDeviceStatus
,
1223 IDirectInput8AImpl_RunControlPanel
,
1224 IDirectInput8AImpl_Initialize
,
1225 IDirectInput8AImpl_FindDevice
,
1226 IDirectInput8AImpl_EnumDevicesBySemantics
,
1227 IDirectInput8AImpl_ConfigureDevices
1230 static const IDirectInput8WVtbl ddi8wvt
= {
1231 IDirectInput8WImpl_QueryInterface
,
1232 IDirectInput8WImpl_AddRef
,
1233 IDirectInput8WImpl_Release
,
1234 IDirectInput8WImpl_CreateDevice
,
1235 IDirectInput8WImpl_EnumDevices
,
1236 IDirectInput8WImpl_GetDeviceStatus
,
1237 IDirectInput8WImpl_RunControlPanel
,
1238 IDirectInput8WImpl_Initialize
,
1239 IDirectInput8WImpl_FindDevice
,
1240 IDirectInput8WImpl_EnumDevicesBySemantics
,
1241 IDirectInput8WImpl_ConfigureDevices
1244 static const IDirectInputJoyConfig8Vtbl JoyConfig8vt
=
1246 JoyConfig8Impl_QueryInterface
,
1247 JoyConfig8Impl_AddRef
,
1248 JoyConfig8Impl_Release
,
1249 JoyConfig8Impl_Acquire
,
1250 JoyConfig8Impl_Unacquire
,
1251 JoyConfig8Impl_SetCooperativeLevel
,
1252 JoyConfig8Impl_SendNotify
,
1253 JoyConfig8Impl_EnumTypes
,
1254 JoyConfig8Impl_GetTypeInfo
,
1255 JoyConfig8Impl_SetTypeInfo
,
1256 JoyConfig8Impl_DeleteType
,
1257 JoyConfig8Impl_GetConfig
,
1258 JoyConfig8Impl_SetConfig
,
1259 JoyConfig8Impl_DeleteConfig
,
1260 JoyConfig8Impl_GetUserValues
,
1261 JoyConfig8Impl_SetUserValues
,
1262 JoyConfig8Impl_AddNewHardware
,
1263 JoyConfig8Impl_OpenTypeKey
,
1264 JoyConfig8Impl_OpenAppStatusKey
1267 /*******************************************************************************
1268 * DirectInput ClassFactory
1272 /* IUnknown fields */
1273 IClassFactory IClassFactory_iface
;
1275 } IClassFactoryImpl
;
1277 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
1279 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
1282 static HRESULT WINAPI
DICF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
1283 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1285 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
1286 return E_NOINTERFACE
;
1289 static ULONG WINAPI
DICF_AddRef(LPCLASSFACTORY iface
) {
1290 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1291 return InterlockedIncrement(&(This
->ref
));
1294 static ULONG WINAPI
DICF_Release(LPCLASSFACTORY iface
) {
1295 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1296 /* static class, won't be freed */
1297 return InterlockedDecrement(&(This
->ref
));
1300 static HRESULT WINAPI
DICF_CreateInstance(
1301 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
1303 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1305 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1306 if ( IsEqualGUID( &IID_IUnknown
, riid
) ||
1307 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
1308 IsEqualGUID( &IID_IDirectInputW
, riid
) ||
1309 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
1310 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
1311 IsEqualGUID( &IID_IDirectInput7A
, riid
) ||
1312 IsEqualGUID( &IID_IDirectInput7W
, riid
) ) {
1313 return create_directinput_instance(riid
, ppobj
, NULL
);
1316 FIXME("(%p,%p,%s,%p) Interface not found!\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1317 return E_NOINTERFACE
;
1320 static HRESULT WINAPI
DICF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
1321 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1322 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
1326 static const IClassFactoryVtbl DICF_Vtbl
= {
1327 DICF_QueryInterface
,
1330 DICF_CreateInstance
,
1333 static IClassFactoryImpl DINPUT_CF
= {{&DICF_Vtbl
}, 1 };
1335 /***********************************************************************
1336 * DllCanUnloadNow (DINPUT.@)
1338 HRESULT WINAPI
DllCanUnloadNow(void)
1343 /***********************************************************************
1344 * DllGetClassObject (DINPUT.@)
1346 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1348 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1349 if ( IsEqualCLSID( &IID_IClassFactory
, riid
) ) {
1351 IClassFactory_AddRef((IClassFactory
*)*ppv
);
1355 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1356 return CLASS_E_CLASSNOTAVAILABLE
;
1359 /***********************************************************************
1360 * DllRegisterServer (DINPUT.@)
1362 HRESULT WINAPI
DllRegisterServer(void)
1364 return __wine_register_resources( DINPUT_instance
);
1367 /***********************************************************************
1368 * DllUnregisterServer (DINPUT.@)
1370 HRESULT WINAPI
DllUnregisterServer(void)
1372 return __wine_unregister_resources( DINPUT_instance
);
1375 /******************************************************************************
1376 * DInput hook thread
1379 static LRESULT CALLBACK
LL_hook_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1381 IDirectInputImpl
*dinput
;
1384 if (code
!= HC_ACTION
) return CallNextHookEx( 0, code
, wparam
, lparam
);
1386 EnterCriticalSection( &dinput_hook_crit
);
1387 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1389 IDirectInputDeviceImpl
*dev
;
1391 EnterCriticalSection( &dinput
->crit
);
1392 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1393 if (dev
->acquired
&& dev
->event_proc
)
1395 TRACE("calling %p->%p (%lx %lx)\n", dev
, dev
->event_proc
, wparam
, lparam
);
1396 skip
|= dev
->event_proc( &dev
->IDirectInputDevice8A_iface
, wparam
, lparam
);
1398 LeaveCriticalSection( &dinput
->crit
);
1400 LeaveCriticalSection( &dinput_hook_crit
);
1402 return skip
? 1 : CallNextHookEx( 0, code
, wparam
, lparam
);
1405 static LRESULT CALLBACK
callwndproc_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1407 CWPSTRUCT
*msg
= (CWPSTRUCT
*)lparam
;
1408 IDirectInputImpl
*dinput
;
1411 if (code
!= HC_ACTION
|| (msg
->message
!= WM_KILLFOCUS
&&
1412 msg
->message
!= WM_ACTIVATEAPP
&& msg
->message
!= WM_ACTIVATE
))
1413 return CallNextHookEx( 0, code
, wparam
, lparam
);
1415 foreground
= GetForegroundWindow();
1417 EnterCriticalSection( &dinput_hook_crit
);
1419 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1421 IDirectInputDeviceImpl
*dev
;
1423 EnterCriticalSection( &dinput
->crit
);
1424 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1426 if (!dev
->acquired
) continue;
1428 if (msg
->hwnd
== dev
->win
&& msg
->hwnd
!= foreground
)
1430 TRACE( "%p window is not foreground - unacquiring %p\n", dev
->win
, dev
);
1431 IDirectInputDevice_Unacquire( &dev
->IDirectInputDevice8A_iface
);
1434 LeaveCriticalSection( &dinput
->crit
);
1436 LeaveCriticalSection( &dinput_hook_crit
);
1438 return CallNextHookEx( 0, code
, wparam
, lparam
);
1441 static DWORD WINAPI
hook_thread_proc(void *param
)
1443 static HHOOK kbd_hook
, mouse_hook
;
1446 /* Force creation of the message queue */
1447 PeekMessageW( &msg
, 0, 0, 0, PM_NOREMOVE
);
1448 SetEvent(*(LPHANDLE
)param
);
1450 while (GetMessageW( &msg
, 0, 0, 0 ))
1452 UINT kbd_cnt
= 0, mice_cnt
= 0;
1454 if (msg
.message
== WM_USER
+0x10)
1456 IDirectInputImpl
*dinput
;
1458 TRACE( "Processing hook change notification lp:%ld\n", msg
.lParam
);
1460 if (!msg
.wParam
&& !msg
.lParam
)
1462 if (kbd_hook
) UnhookWindowsHookEx( kbd_hook
);
1463 if (mouse_hook
) UnhookWindowsHookEx( mouse_hook
);
1464 kbd_hook
= mouse_hook
= NULL
;
1468 EnterCriticalSection( &dinput_hook_crit
);
1470 /* Count acquired keyboards and mice*/
1471 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1473 IDirectInputDeviceImpl
*dev
;
1475 EnterCriticalSection( &dinput
->crit
);
1476 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1478 if (!dev
->acquired
|| !dev
->event_proc
) continue;
1480 if (IsEqualGUID( &dev
->guid
, &GUID_SysKeyboard
) ||
1481 IsEqualGUID( &dev
->guid
, &DInput_Wine_Keyboard_GUID
))
1484 if (IsEqualGUID( &dev
->guid
, &GUID_SysMouse
) ||
1485 IsEqualGUID( &dev
->guid
, &DInput_Wine_Mouse_GUID
))
1488 LeaveCriticalSection( &dinput
->crit
);
1490 LeaveCriticalSection( &dinput_hook_crit
);
1492 if (kbd_cnt
&& !kbd_hook
)
1493 kbd_hook
= SetWindowsHookExW( WH_KEYBOARD_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1494 else if (!kbd_cnt
&& kbd_hook
)
1496 UnhookWindowsHookEx( kbd_hook
);
1500 if (mice_cnt
&& !mouse_hook
)
1501 mouse_hook
= SetWindowsHookExW( WH_MOUSE_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1502 else if (!mice_cnt
&& mouse_hook
)
1504 UnhookWindowsHookEx( mouse_hook
);
1508 TranslateMessage(&msg
);
1509 DispatchMessageW(&msg
);
1515 static DWORD hook_thread_id
;
1517 static CRITICAL_SECTION_DEBUG dinput_critsect_debug
=
1519 0, 0, &dinput_hook_crit
,
1520 { &dinput_critsect_debug
.ProcessLocksList
, &dinput_critsect_debug
.ProcessLocksList
},
1521 0, 0, { (DWORD_PTR
)(__FILE__
": dinput_hook_crit") }
1523 static CRITICAL_SECTION dinput_hook_crit
= { &dinput_critsect_debug
, -1, 0, 0, 0, 0 };
1525 static BOOL
check_hook_thread(void)
1527 static HANDLE hook_thread
;
1529 EnterCriticalSection(&dinput_hook_crit
);
1531 TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list
));
1532 if (!list_empty(&direct_input_list
) && !hook_thread
)
1536 event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1537 hook_thread
= CreateThread(NULL
, 0, hook_thread_proc
, &event
, 0, &hook_thread_id
);
1538 if (event
&& hook_thread
)
1542 handles
[1] = hook_thread
;
1543 WaitForMultipleObjects(2, handles
, FALSE
, INFINITE
);
1545 LeaveCriticalSection(&dinput_hook_crit
);
1548 else if (list_empty(&direct_input_list
) && hook_thread
)
1550 DWORD tid
= hook_thread_id
;
1553 PostThreadMessageW(tid
, WM_USER
+0x10, 0, 0);
1554 LeaveCriticalSection(&dinput_hook_crit
);
1556 /* wait for hook thread to exit */
1557 WaitForSingleObject(hook_thread
, INFINITE
);
1558 CloseHandle(hook_thread
);
1562 LeaveCriticalSection(&dinput_hook_crit
);
1564 return hook_thread_id
!= 0;
1567 void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface
)
1569 static HHOOK callwndproc_hook
;
1570 static ULONG foreground_cnt
;
1571 IDirectInputDeviceImpl
*dev
= impl_from_IDirectInputDevice8W(iface
);
1573 EnterCriticalSection(&dinput_hook_crit
);
1575 if (dev
->dwCoopLevel
& DISCL_FOREGROUND
)
1583 if (foreground_cnt
&& !callwndproc_hook
)
1584 callwndproc_hook
= SetWindowsHookExW( WH_CALLWNDPROC
, callwndproc_proc
,
1585 DINPUT_instance
, GetCurrentThreadId() );
1586 else if (!foreground_cnt
&& callwndproc_hook
)
1588 UnhookWindowsHookEx( callwndproc_hook
);
1589 callwndproc_hook
= NULL
;
1592 PostThreadMessageW( hook_thread_id
, WM_USER
+0x10, 1, 0 );
1594 LeaveCriticalSection(&dinput_hook_crit
);
1597 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserv
)
1601 case DLL_PROCESS_ATTACH
:
1602 DisableThreadLibraryCalls(inst
);
1603 DINPUT_instance
= inst
;
1605 case DLL_PROCESS_DETACH
:
1606 DeleteCriticalSection(&dinput_hook_crit
);