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
)
216 TRACE("DIEDFL_ALLDEVICES\n");
219 for (i
= 0; i
< (sizeof(flags
) / sizeof(flags
[0])); i
++)
220 if (flags
[i
].mask
& dwFlags
)
221 TRACE("%s ",flags
[i
].name
);
226 static void _dump_diactionformatA(LPDIACTIONFORMATA lpdiActionFormat
) {
229 FIXME("diaf.dwSize = %d\n", lpdiActionFormat
->dwSize
);
230 FIXME("diaf.dwActionSize = %d\n", lpdiActionFormat
->dwActionSize
);
231 FIXME("diaf.dwDataSize = %d\n", lpdiActionFormat
->dwDataSize
);
232 FIXME("diaf.dwNumActions = %d\n", lpdiActionFormat
->dwNumActions
);
233 FIXME("diaf.rgoAction = %p\n", lpdiActionFormat
->rgoAction
);
234 FIXME("diaf.guidActionMap = %s\n", debugstr_guid(&lpdiActionFormat
->guidActionMap
));
235 FIXME("diaf.dwGenre = 0x%08x\n", lpdiActionFormat
->dwGenre
);
236 FIXME("diaf.dwBufferSize = %d\n", lpdiActionFormat
->dwBufferSize
);
237 FIXME("diaf.lAxisMin = %d\n", lpdiActionFormat
->lAxisMin
);
238 FIXME("diaf.lAxisMax = %d\n", lpdiActionFormat
->lAxisMax
);
239 FIXME("diaf.hInstString = %p\n", lpdiActionFormat
->hInstString
);
240 FIXME("diaf.ftTimeStamp ...\n");
241 FIXME("diaf.dwCRC = 0x%x\n", lpdiActionFormat
->dwCRC
);
242 FIXME("diaf.tszActionMap = %s\n", debugstr_a(lpdiActionFormat
->tszActionMap
));
243 for (i
= 0; i
< lpdiActionFormat
->dwNumActions
; i
++)
245 FIXME("diaf.rgoAction[%u]:\n", i
);
246 FIXME("\tuAppData=0x%lx\n", lpdiActionFormat
->rgoAction
[i
].uAppData
);
247 FIXME("\tdwSemantic=0x%08x\n", lpdiActionFormat
->rgoAction
[i
].dwSemantic
);
248 FIXME("\tdwFlags=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwFlags
);
249 FIXME("\tszActionName=%s\n", debugstr_a(lpdiActionFormat
->rgoAction
[i
].u
.lptszActionName
));
250 FIXME("\tguidInstance=%s\n", debugstr_guid(&lpdiActionFormat
->rgoAction
[i
].guidInstance
));
251 FIXME("\tdwObjID=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwObjID
);
252 FIXME("\tdwHow=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwHow
);
256 void _copy_diactionformatAtoW(LPDIACTIONFORMATW to
, LPDIACTIONFORMATA from
)
260 to
->dwSize
= sizeof(DIACTIONFORMATW
);
261 to
->dwActionSize
= sizeof(DIACTIONW
);
262 to
->dwDataSize
= from
->dwDataSize
;
263 to
->dwNumActions
= from
->dwNumActions
;
264 to
->guidActionMap
= from
->guidActionMap
;
265 to
->dwGenre
= from
->dwGenre
;
266 to
->dwBufferSize
= from
->dwBufferSize
;
267 to
->lAxisMin
= from
->lAxisMin
;
268 to
->lAxisMax
= from
->lAxisMax
;
269 to
->dwCRC
= from
->dwCRC
;
270 to
->ftTimeStamp
= from
->ftTimeStamp
;
272 for (i
=0; i
< to
->dwNumActions
; i
++)
274 to
->rgoAction
[i
].uAppData
= from
->rgoAction
[i
].uAppData
;
275 to
->rgoAction
[i
].dwSemantic
= from
->rgoAction
[i
].dwSemantic
;
276 to
->rgoAction
[i
].dwFlags
= from
->rgoAction
[i
].dwFlags
;
277 to
->rgoAction
[i
].guidInstance
= from
->rgoAction
[i
].guidInstance
;
278 to
->rgoAction
[i
].dwObjID
= from
->rgoAction
[i
].dwObjID
;
279 to
->rgoAction
[i
].dwHow
= from
->rgoAction
[i
].dwHow
;
283 void _copy_diactionformatWtoA(LPDIACTIONFORMATA to
, LPDIACTIONFORMATW from
)
287 to
->dwSize
= sizeof(DIACTIONFORMATA
);
288 to
->dwActionSize
= sizeof(DIACTIONA
);
289 to
->dwDataSize
= from
->dwDataSize
;
290 to
->dwNumActions
= from
->dwNumActions
;
291 to
->guidActionMap
= from
->guidActionMap
;
292 to
->dwGenre
= from
->dwGenre
;
293 to
->dwBufferSize
= from
->dwBufferSize
;
294 to
->lAxisMin
= from
->lAxisMin
;
295 to
->lAxisMax
= from
->lAxisMax
;
296 to
->dwCRC
= from
->dwCRC
;
297 to
->ftTimeStamp
= from
->ftTimeStamp
;
299 for (i
=0; i
< to
->dwNumActions
; i
++)
301 to
->rgoAction
[i
].uAppData
= from
->rgoAction
[i
].uAppData
;
302 to
->rgoAction
[i
].dwSemantic
= from
->rgoAction
[i
].dwSemantic
;
303 to
->rgoAction
[i
].dwFlags
= from
->rgoAction
[i
].dwFlags
;
304 to
->rgoAction
[i
].guidInstance
= from
->rgoAction
[i
].guidInstance
;
305 to
->rgoAction
[i
].dwObjID
= from
->rgoAction
[i
].dwObjID
;
306 to
->rgoAction
[i
].dwHow
= from
->rgoAction
[i
].dwHow
;
310 /* _diactionformat_priority
312 * Given a DIACTIONFORMAT structure and a DI genre, returns the enumeration
313 * priority. Joysticks should pass the game genre, and mouse or keyboard their
314 * respective DI*_MASK
316 static DWORD
_diactionformat_priorityA(LPDIACTIONFORMATA lpdiaf
, DWORD genre
)
319 DWORD priorityFlags
= 0;
321 /* If there's at least one action for the device it's priority 1 */
322 for(i
=0; i
< lpdiaf
->dwActionSize
; i
++)
323 if ((lpdiaf
->rgoAction
[i
].dwSemantic
& genre
) == genre
)
324 priorityFlags
|= DIEDBS_MAPPEDPRI1
;
326 return priorityFlags
;
329 static DWORD
_diactionformat_priorityW(LPDIACTIONFORMATW lpdiaf
, DWORD genre
)
332 DWORD priorityFlags
= 0;
334 /* If there's at least one action for the device it's priority 1 */
335 for(i
=0; i
< lpdiaf
->dwActionSize
; i
++)
336 if ((lpdiaf
->rgoAction
[i
].dwSemantic
& genre
) == genre
)
337 priorityFlags
|= DIEDBS_MAPPEDPRI1
;
339 return priorityFlags
;
342 /******************************************************************************
343 * IDirectInputA_EnumDevices
345 static HRESULT WINAPI
IDirectInputAImpl_EnumDevices(
346 LPDIRECTINPUT7A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
347 LPVOID pvRef
, DWORD dwFlags
)
349 IDirectInputImpl
*This
= impl_from_IDirectInput7A(iface
);
350 DIDEVICEINSTANCEA devInstance
;
354 TRACE("(this=%p,0x%04x '%s',%p,%p,%04x)\n",
355 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
),
356 lpCallback
, pvRef
, dwFlags
);
357 _dump_EnumDevices_dwFlags(dwFlags
);
360 return DIERR_INVALIDPARAM
;
362 if (!This
->initialized
)
363 return DIERR_NOTINITIALIZED
;
365 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
366 if (!dinput_devices
[i
]->enum_deviceA
) continue;
367 for (j
= 0, r
= -1; r
!= 0; j
++) {
368 devInstance
.dwSize
= sizeof(devInstance
);
369 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
370 if ((r
= dinput_devices
[i
]->enum_deviceA(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
))) {
371 if (lpCallback(&devInstance
,pvRef
) == DIENUM_STOP
)
379 /******************************************************************************
380 * IDirectInputW_EnumDevices
382 static HRESULT WINAPI
IDirectInputWImpl_EnumDevices(
383 LPDIRECTINPUT7W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
384 LPVOID pvRef
, DWORD dwFlags
)
386 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
387 DIDEVICEINSTANCEW devInstance
;
391 TRACE("(this=%p,0x%04x '%s',%p,%p,%04x)\n",
392 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
),
393 lpCallback
, pvRef
, dwFlags
);
394 _dump_EnumDevices_dwFlags(dwFlags
);
397 return DIERR_INVALIDPARAM
;
399 if (!This
->initialized
)
400 return DIERR_NOTINITIALIZED
;
402 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
403 if (!dinput_devices
[i
]->enum_deviceW
) continue;
404 for (j
= 0, r
= -1; r
!= 0; j
++) {
405 devInstance
.dwSize
= sizeof(devInstance
);
406 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
407 if ((r
= dinput_devices
[i
]->enum_deviceW(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
))) {
408 if (lpCallback(&devInstance
,pvRef
) == DIENUM_STOP
)
417 static ULONG WINAPI
IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface
)
419 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
420 ULONG ref
= InterlockedIncrement(&This
->ref
);
422 TRACE( "(%p) incrementing from %d\n", This
, ref
- 1);
426 static ULONG WINAPI
IDirectInputWImpl_AddRef(LPDIRECTINPUT7W iface
)
428 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
429 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
432 static ULONG WINAPI
IDirectInputAImpl_Release(LPDIRECTINPUT7A iface
)
434 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
435 ULONG ref
= InterlockedDecrement( &This
->ref
);
437 TRACE( "(%p) releasing from %d\n", This
, ref
+ 1 );
441 uninitialize_directinput_instance( This
);
442 HeapFree( GetProcessHeap(), 0, This
);
448 static ULONG WINAPI
IDirectInputWImpl_Release(LPDIRECTINPUT7W iface
)
450 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
451 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
454 static HRESULT WINAPI
IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface
, REFIID riid
, LPVOID
*ppobj
)
456 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
458 TRACE( "(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
463 if (IsEqualGUID( &IID_IUnknown
, riid
) ||
464 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
465 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
466 IsEqualGUID( &IID_IDirectInput7A
, riid
))
468 *ppobj
= &This
->IDirectInput7A_iface
;
469 IUnknown_AddRef( (IUnknown
*)*ppobj
);
474 if (IsEqualGUID( &IID_IDirectInputW
, riid
) ||
475 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
476 IsEqualGUID( &IID_IDirectInput7W
, riid
))
478 *ppobj
= &This
->IDirectInput7W_iface
;
479 IUnknown_AddRef( (IUnknown
*)*ppobj
);
484 if (IsEqualGUID( &IID_IDirectInput8A
, riid
))
486 *ppobj
= &This
->IDirectInput8A_iface
;
487 IUnknown_AddRef( (IUnknown
*)*ppobj
);
492 if (IsEqualGUID( &IID_IDirectInput8W
, riid
))
494 *ppobj
= &This
->IDirectInput8W_iface
;
495 IUnknown_AddRef( (IUnknown
*)*ppobj
);
500 if (IsEqualGUID( &IID_IDirectInputJoyConfig8
, riid
))
502 *ppobj
= &This
->IDirectInputJoyConfig8_iface
;
503 IUnknown_AddRef( (IUnknown
*)*ppobj
);
508 FIXME( "Unsupported interface: %s\n", debugstr_guid(riid
));
510 return E_NOINTERFACE
;
513 static HRESULT WINAPI
IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface
, REFIID riid
, LPVOID
*ppobj
)
515 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
516 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
519 static HRESULT
initialize_directinput_instance(IDirectInputImpl
*This
, DWORD dwVersion
)
521 if (!This
->initialized
)
523 This
->dwVersion
= dwVersion
;
524 This
->evsequence
= 1;
526 InitializeCriticalSection( &This
->crit
);
527 This
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IDirectInputImpl*->crit");
529 list_init( &This
->devices_list
);
531 /* Add self to the list of the IDirectInputs */
532 EnterCriticalSection( &dinput_hook_crit
);
533 list_add_head( &direct_input_list
, &This
->entry
);
534 LeaveCriticalSection( &dinput_hook_crit
);
536 This
->initialized
= TRUE
;
538 if (!check_hook_thread())
540 uninitialize_directinput_instance( This
);
541 return DIERR_GENERIC
;
548 static void uninitialize_directinput_instance(IDirectInputImpl
*This
)
550 if (This
->initialized
)
552 /* Remove self from the list of the IDirectInputs */
553 EnterCriticalSection( &dinput_hook_crit
);
554 list_remove( &This
->entry
);
555 LeaveCriticalSection( &dinput_hook_crit
);
559 This
->crit
.DebugInfo
->Spare
[0] = 0;
560 DeleteCriticalSection( &This
->crit
);
562 This
->initialized
= FALSE
;
566 enum directinput_versions
568 DIRECTINPUT_VERSION_300
= 0x0300,
569 DIRECTINPUT_VERSION_500
= 0x0500,
570 DIRECTINPUT_VERSION_50A
= 0x050A,
571 DIRECTINPUT_VERSION_5B2
= 0x05B2,
572 DIRECTINPUT_VERSION_602
= 0x0602,
573 DIRECTINPUT_VERSION_61A
= 0x061A,
574 DIRECTINPUT_VERSION_700
= 0x0700,
577 static HRESULT WINAPI
IDirectInputAImpl_Initialize(LPDIRECTINPUT7A iface
, HINSTANCE hinst
, DWORD version
)
579 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
581 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
584 return DIERR_INVALIDPARAM
;
585 else if (version
== 0)
586 return DIERR_NOTINITIALIZED
;
587 else if (version
> DIRECTINPUT_VERSION_700
)
588 return DIERR_OLDDIRECTINPUTVERSION
;
589 else if (version
!= DIRECTINPUT_VERSION_300
&& version
!= DIRECTINPUT_VERSION_500
&&
590 version
!= DIRECTINPUT_VERSION_50A
&& version
!= DIRECTINPUT_VERSION_5B2
&&
591 version
!= DIRECTINPUT_VERSION_602
&& version
!= DIRECTINPUT_VERSION_61A
&&
592 version
!= DIRECTINPUT_VERSION_700
&& version
!= DIRECTINPUT_VERSION
)
593 return DIERR_BETADIRECTINPUTVERSION
;
595 return initialize_directinput_instance(This
, version
);
598 static HRESULT WINAPI
IDirectInputWImpl_Initialize(LPDIRECTINPUT7W iface
, HINSTANCE hinst
, DWORD x
)
600 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
601 return IDirectInputAImpl_Initialize( &This
->IDirectInput7A_iface
, hinst
, x
);
604 static HRESULT WINAPI
IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface
, REFGUID rguid
)
606 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
608 LPDIRECTINPUTDEVICEA device
;
610 TRACE( "(%p)->(%s)\n", This
, debugstr_guid(rguid
) );
612 if (!This
->initialized
)
613 return DIERR_NOTINITIALIZED
;
615 hr
= IDirectInput_CreateDevice( iface
, rguid
, &device
, NULL
);
616 if (hr
!= DI_OK
) return DI_NOTATTACHED
;
618 IUnknown_Release( device
);
623 static HRESULT WINAPI
IDirectInputWImpl_GetDeviceStatus(LPDIRECTINPUT7W iface
, REFGUID rguid
)
625 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
626 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
629 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface
,
633 WCHAR control_exeW
[] = {'c','o','n','t','r','o','l','.','e','x','e',0};
634 STARTUPINFOW si
= {0};
635 PROCESS_INFORMATION pi
;
637 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
639 TRACE( "(%p)->(%p, %08x)\n", This
, hwndOwner
, dwFlags
);
641 if (hwndOwner
&& !IsWindow(hwndOwner
))
645 return DIERR_INVALIDPARAM
;
647 if (!This
->initialized
)
648 return DIERR_NOTINITIALIZED
;
650 if (!CreateProcessW(NULL
, control_exeW
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
651 return HRESULT_FROM_WIN32(GetLastError());
656 static HRESULT WINAPI
IDirectInputWImpl_RunControlPanel(LPDIRECTINPUT7W iface
, HWND hwndOwner
, DWORD dwFlags
)
658 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
659 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
662 static HRESULT WINAPI
IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
663 LPCSTR pszName
, LPGUID pguidInstance
)
665 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
667 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), pszName
, pguidInstance
);
672 static HRESULT WINAPI
IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
673 LPCWSTR pszName
, LPGUID pguidInstance
)
675 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
677 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), debugstr_w(pszName
), pguidInstance
);
682 static HRESULT
create_device(IDirectInputImpl
*This
, REFGUID rguid
, REFIID riid
, LPVOID
*pvOut
, BOOL unicode
)
689 if (!rguid
|| !pvOut
)
692 if (!This
->initialized
)
693 return DIERR_NOTINITIALIZED
;
695 /* Loop on all the devices to see if anyone matches the given GUID */
696 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
700 if (!dinput_devices
[i
]->create_device
) continue;
701 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, riid
, pvOut
, unicode
)) == DI_OK
)
705 WARN("invalid device GUID %s\n", debugstr_guid(rguid
));
706 return DIERR_DEVICENOTREG
;
709 static HRESULT WINAPI
IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface
, REFGUID rguid
,
710 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
712 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
714 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
716 return create_device(This
, rguid
, riid
, pvOut
, FALSE
);
719 static HRESULT WINAPI
IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface
, REFGUID rguid
,
720 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
722 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
724 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
726 return create_device(This
, rguid
, riid
, pvOut
, TRUE
);
729 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
730 LPDIRECTINPUTDEVICEA
* pdev
, LPUNKNOWN punk
)
732 return IDirectInput7AImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
735 static HRESULT WINAPI
IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
736 LPDIRECTINPUTDEVICEW
* pdev
, LPUNKNOWN punk
)
738 return IDirectInput7WImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
741 /*******************************************************************************
745 static ULONG WINAPI
IDirectInput8AImpl_AddRef(LPDIRECTINPUT8A iface
)
747 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
748 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
751 static ULONG WINAPI
IDirectInput8WImpl_AddRef(LPDIRECTINPUT8W iface
)
753 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
754 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
757 static HRESULT WINAPI
IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface
, REFIID riid
, LPVOID
*ppobj
)
759 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
760 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
763 static HRESULT WINAPI
IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W iface
, REFIID riid
, LPVOID
*ppobj
)
765 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
766 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
769 static ULONG WINAPI
IDirectInput8AImpl_Release(LPDIRECTINPUT8A iface
)
771 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
772 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
775 static ULONG WINAPI
IDirectInput8WImpl_Release(LPDIRECTINPUT8W iface
)
777 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
778 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
781 static HRESULT WINAPI
IDirectInput8AImpl_CreateDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
,
782 LPDIRECTINPUTDEVICE8A
* pdev
, LPUNKNOWN punk
)
784 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
785 return IDirectInput7AImpl_CreateDeviceEx( &This
->IDirectInput7A_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
788 static HRESULT WINAPI
IDirectInput8WImpl_CreateDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
,
789 LPDIRECTINPUTDEVICE8W
* pdev
, LPUNKNOWN punk
)
791 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
792 return IDirectInput7WImpl_CreateDeviceEx( &This
->IDirectInput7W_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
795 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevices(LPDIRECTINPUT8A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
796 LPVOID pvRef
, DWORD dwFlags
)
798 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
799 return IDirectInputAImpl_EnumDevices( &This
->IDirectInput7A_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
802 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
803 LPVOID pvRef
, DWORD dwFlags
)
805 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
806 return IDirectInputWImpl_EnumDevices( &This
->IDirectInput7W_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
809 static HRESULT WINAPI
IDirectInput8AImpl_GetDeviceStatus(LPDIRECTINPUT8A iface
, REFGUID rguid
)
811 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
812 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
815 static HRESULT WINAPI
IDirectInput8WImpl_GetDeviceStatus(LPDIRECTINPUT8W iface
, REFGUID rguid
)
817 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
818 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
821 static HRESULT WINAPI
IDirectInput8AImpl_RunControlPanel(LPDIRECTINPUT8A iface
, HWND hwndOwner
, DWORD dwFlags
)
823 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
824 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
827 static HRESULT WINAPI
IDirectInput8WImpl_RunControlPanel(LPDIRECTINPUT8W iface
, HWND hwndOwner
, DWORD dwFlags
)
829 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
830 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
833 static HRESULT WINAPI
IDirectInput8AImpl_Initialize(LPDIRECTINPUT8A iface
, HINSTANCE hinst
, DWORD version
)
835 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
837 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
840 return DIERR_INVALIDPARAM
;
841 else if (version
== 0)
842 return DIERR_NOTINITIALIZED
;
843 else if (version
< DIRECTINPUT_VERSION
)
844 return DIERR_BETADIRECTINPUTVERSION
;
845 else if (version
> DIRECTINPUT_VERSION
)
846 return DIERR_OLDDIRECTINPUTVERSION
;
848 return initialize_directinput_instance(This
, version
);
851 static HRESULT WINAPI
IDirectInput8WImpl_Initialize(LPDIRECTINPUT8W iface
, HINSTANCE hinst
, DWORD version
)
853 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
854 return IDirectInput8AImpl_Initialize( &This
->IDirectInput8A_iface
, hinst
, version
);
857 static HRESULT WINAPI
IDirectInput8AImpl_FindDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
, LPCSTR pszName
, LPGUID pguidInstance
)
859 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
860 return IDirectInput2AImpl_FindDevice( &This
->IDirectInput7A_iface
, rguid
, pszName
, pguidInstance
);
863 static HRESULT WINAPI
IDirectInput8WImpl_FindDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
, LPCWSTR pszName
, LPGUID pguidInstance
)
865 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
866 return IDirectInput2WImpl_FindDevice( &This
->IDirectInput7W_iface
, rguid
, pszName
, pguidInstance
);
869 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevicesBySemantics(
870 LPDIRECTINPUT8A iface
, LPCSTR ptszUserName
, LPDIACTIONFORMATA lpdiActionFormat
,
871 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback
,
872 LPVOID pvRef
, DWORD dwFlags
875 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
876 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
877 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
878 DIDEVICEINSTANCEA didevi
;
879 LPDIRECTINPUTDEVICE8A lpdid
;
884 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_a(ptszUserName
), lpdiActionFormat
,
885 lpCallback
, pvRef
, dwFlags
);
886 #define X(x) if (dwFlags & x) FIXME("\tdwFlags |= "#x"\n");
887 X(DIEDBSFL_ATTACHEDONLY
)
889 X(DIEDBSFL_FORCEFEEDBACK
)
890 X(DIEDBSFL_AVAILABLEDEVICES
)
891 X(DIEDBSFL_MULTIMICEKEYBOARDS
)
892 X(DIEDBSFL_NONGAMINGDEVICES
)
895 _dump_diactionformatA(lpdiActionFormat
);
897 didevi
.dwSize
= sizeof(didevi
);
899 /* Enumerate all the joysticks */
900 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
904 if (!dinput_devices
[i
]->enum_deviceA
) continue;
906 for (j
= 0, enumSuccess
= -1; enumSuccess
!= 0; j
++)
908 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
910 callbackFlags
= _diactionformat_priorityA(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
911 /* Default behavior is to enumerate attached game controllers */
912 enumSuccess
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
915 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
917 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
923 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
925 /* Enumerate keyboard and mouse */
926 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
928 callbackFlags
= _diactionformat_priorityA(lpdiActionFormat
, actionMasks
[i
]);
930 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
931 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
933 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
940 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevicesBySemantics(
941 LPDIRECTINPUT8W iface
, LPCWSTR ptszUserName
, LPDIACTIONFORMATW lpdiActionFormat
,
942 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback
,
943 LPVOID pvRef
, DWORD dwFlags
946 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
947 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
948 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
949 DIDEVICEINSTANCEW didevi
;
950 LPDIRECTINPUTDEVICE8W lpdid
;
954 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_w(ptszUserName
), lpdiActionFormat
,
955 lpCallback
, pvRef
, dwFlags
);
957 didevi
.dwSize
= sizeof(didevi
);
959 /* Enumerate all the joysticks */
960 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
964 if (!dinput_devices
[i
]->enum_deviceW
) continue;
966 for (j
= 0, enumSuccess
= -1; enumSuccess
!= 0; j
++)
968 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
970 callbackFlags
= _diactionformat_priorityW(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
971 /* Default behavior is to enumerate attached game controllers */
972 enumSuccess
= dinput_devices
[i
]->enum_deviceW(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
975 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
977 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
983 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
985 /* Enumerate keyboard and mouse */
986 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
988 callbackFlags
= _diactionformat_priorityW(lpdiActionFormat
, actionMasks
[i
]);
990 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
991 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
993 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
1000 static HRESULT WINAPI
IDirectInput8WImpl_ConfigureDevices(
1001 LPDIRECTINPUT8W iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1002 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1005 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
1007 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1009 /* Call helper function in config.c to do the real work */
1010 return _configure_devices(iface
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1013 static HRESULT WINAPI
IDirectInput8AImpl_ConfigureDevices(
1014 LPDIRECTINPUT8A iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1015 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1018 IDirectInputImpl
*This
= impl_from_IDirectInput8A(iface
);
1019 DIACTIONFORMATW diafW
;
1020 DICONFIGUREDEVICESPARAMSW diCDParamsW
;
1024 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1026 /* Copy parameters */
1027 diCDParamsW
.dwSize
= sizeof(DICONFIGUREDEVICESPARAMSW
);
1028 diCDParamsW
.dwcFormats
= lpdiCDParams
->dwcFormats
;
1029 diCDParamsW
.lprgFormats
= &diafW
;
1030 diCDParamsW
.hwnd
= lpdiCDParams
->hwnd
;
1032 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiCDParams
->lprgFormats
->dwNumActions
);
1033 _copy_diactionformatAtoW(&diafW
, lpdiCDParams
->lprgFormats
);
1035 /* Copy action names */
1036 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1038 const char* from
= lpdiCDParams
->lprgFormats
->rgoAction
[i
].u
.lptszActionName
;
1039 int len
= MultiByteToWideChar(CP_ACP
, 0, from
, -1, NULL
, 0);
1040 WCHAR
*to
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*len
);
1042 MultiByteToWideChar(CP_ACP
, 0, from
, -1, to
, len
);
1043 diafW
.rgoAction
[i
].u
.lptszActionName
= to
;
1046 hr
= IDirectInput8WImpl_ConfigureDevices(&This
->IDirectInput8W_iface
, lpdiCallback
, &diCDParamsW
, dwFlags
, pvRefData
);
1048 /* Copy back configuration */
1050 _copy_diactionformatWtoA(lpdiCDParams
->lprgFormats
, &diafW
);
1053 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1054 HeapFree(GetProcessHeap(), 0, (void*) diafW
.rgoAction
[i
].u
.lptszActionName
);
1056 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
1061 /*****************************************************************************
1062 * IDirectInputJoyConfig8 interface
1065 static inline IDirectInputImpl
*impl_from_IDirectInputJoyConfig8(IDirectInputJoyConfig8
*iface
)
1067 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInputJoyConfig8_iface
);
1070 static HRESULT WINAPI
JoyConfig8Impl_QueryInterface(IDirectInputJoyConfig8
*iface
, REFIID riid
, void** ppobj
)
1072 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1073 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
1076 static ULONG WINAPI
JoyConfig8Impl_AddRef(IDirectInputJoyConfig8
*iface
)
1078 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1079 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
1082 static ULONG WINAPI
JoyConfig8Impl_Release(IDirectInputJoyConfig8
*iface
)
1084 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1085 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
1088 static HRESULT WINAPI
JoyConfig8Impl_Acquire(IDirectInputJoyConfig8
*iface
)
1090 FIXME( "(%p): stub!\n", iface
);
1094 static HRESULT WINAPI
JoyConfig8Impl_Unacquire(IDirectInputJoyConfig8
*iface
)
1096 FIXME( "(%p): stub!\n", iface
);
1100 static HRESULT WINAPI
JoyConfig8Impl_SetCooperativeLevel(IDirectInputJoyConfig8
*iface
, HWND hwnd
, DWORD flags
)
1102 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, hwnd
, flags
);
1106 static HRESULT WINAPI
JoyConfig8Impl_SendNotify(IDirectInputJoyConfig8
*iface
)
1108 FIXME( "(%p): stub!\n", iface
);
1112 static HRESULT WINAPI
JoyConfig8Impl_EnumTypes(IDirectInputJoyConfig8
*iface
, LPDIJOYTYPECALLBACK cb
, void *ref
)
1114 FIXME( "(%p)->(%p, %p): stub!\n", iface
, cb
, ref
);
1118 static HRESULT WINAPI
JoyConfig8Impl_GetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPDIJOYTYPEINFO info
, DWORD flags
)
1120 FIXME( "(%p)->(%s, %p, 0x%08x): stub!\n", iface
, debugstr_w(name
), info
, flags
);
1124 static HRESULT WINAPI
JoyConfig8Impl_SetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPCDIJOYTYPEINFO info
, DWORD flags
,
1127 FIXME( "(%p)->(%s, %p, 0x%08x, %s): stub!\n", iface
, debugstr_w(name
), info
, flags
, debugstr_w(new_name
) );
1131 static HRESULT WINAPI
JoyConfig8Impl_DeleteType(IDirectInputJoyConfig8
*iface
, LPCWSTR name
)
1133 FIXME( "(%p)->(%s): stub!\n", iface
, debugstr_w(name
) );
1137 static HRESULT WINAPI
JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPDIJOYCONFIG info
, DWORD flags
)
1139 FIXME( "(%p)->(%d, %p, 0x%08x): stub!\n", iface
, id
, info
, flags
);
1143 static HRESULT WINAPI
JoyConfig8Impl_SetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPCDIJOYCONFIG info
, DWORD flags
)
1145 FIXME( "(%p)->(%d, %p, 0x%08x): stub!\n", iface
, id
, info
, flags
);
1149 static HRESULT WINAPI
JoyConfig8Impl_DeleteConfig(IDirectInputJoyConfig8
*iface
, UINT id
)
1151 FIXME( "(%p)->(%d): stub!\n", iface
, id
);
1155 static HRESULT WINAPI
JoyConfig8Impl_GetUserValues(IDirectInputJoyConfig8
*iface
, LPDIJOYUSERVALUES info
, DWORD flags
)
1157 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1161 static HRESULT WINAPI
JoyConfig8Impl_SetUserValues(IDirectInputJoyConfig8
*iface
, LPCDIJOYUSERVALUES info
, DWORD flags
)
1163 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1167 static HRESULT WINAPI
JoyConfig8Impl_AddNewHardware(IDirectInputJoyConfig8
*iface
, HWND hwnd
, REFGUID guid
)
1169 FIXME( "(%p)->(%p, %s): stub!\n", iface
, hwnd
, debugstr_guid(guid
) );
1173 static HRESULT WINAPI
JoyConfig8Impl_OpenTypeKey(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, DWORD security
, PHKEY key
)
1175 FIXME( "(%p)->(%s, 0x%08x, %p): stub!\n", iface
, debugstr_w(name
), security
, key
);
1179 static HRESULT WINAPI
JoyConfig8Impl_OpenAppStatusKey(IDirectInputJoyConfig8
*iface
, PHKEY key
)
1181 FIXME( "(%p)->(%p): stub!\n", iface
, key
);
1185 static const IDirectInput7AVtbl ddi7avt
= {
1186 IDirectInputAImpl_QueryInterface
,
1187 IDirectInputAImpl_AddRef
,
1188 IDirectInputAImpl_Release
,
1189 IDirectInputAImpl_CreateDevice
,
1190 IDirectInputAImpl_EnumDevices
,
1191 IDirectInputAImpl_GetDeviceStatus
,
1192 IDirectInputAImpl_RunControlPanel
,
1193 IDirectInputAImpl_Initialize
,
1194 IDirectInput2AImpl_FindDevice
,
1195 IDirectInput7AImpl_CreateDeviceEx
1198 static const IDirectInput7WVtbl ddi7wvt
= {
1199 IDirectInputWImpl_QueryInterface
,
1200 IDirectInputWImpl_AddRef
,
1201 IDirectInputWImpl_Release
,
1202 IDirectInputWImpl_CreateDevice
,
1203 IDirectInputWImpl_EnumDevices
,
1204 IDirectInputWImpl_GetDeviceStatus
,
1205 IDirectInputWImpl_RunControlPanel
,
1206 IDirectInputWImpl_Initialize
,
1207 IDirectInput2WImpl_FindDevice
,
1208 IDirectInput7WImpl_CreateDeviceEx
1211 static const IDirectInput8AVtbl ddi8avt
= {
1212 IDirectInput8AImpl_QueryInterface
,
1213 IDirectInput8AImpl_AddRef
,
1214 IDirectInput8AImpl_Release
,
1215 IDirectInput8AImpl_CreateDevice
,
1216 IDirectInput8AImpl_EnumDevices
,
1217 IDirectInput8AImpl_GetDeviceStatus
,
1218 IDirectInput8AImpl_RunControlPanel
,
1219 IDirectInput8AImpl_Initialize
,
1220 IDirectInput8AImpl_FindDevice
,
1221 IDirectInput8AImpl_EnumDevicesBySemantics
,
1222 IDirectInput8AImpl_ConfigureDevices
1225 static const IDirectInput8WVtbl ddi8wvt
= {
1226 IDirectInput8WImpl_QueryInterface
,
1227 IDirectInput8WImpl_AddRef
,
1228 IDirectInput8WImpl_Release
,
1229 IDirectInput8WImpl_CreateDevice
,
1230 IDirectInput8WImpl_EnumDevices
,
1231 IDirectInput8WImpl_GetDeviceStatus
,
1232 IDirectInput8WImpl_RunControlPanel
,
1233 IDirectInput8WImpl_Initialize
,
1234 IDirectInput8WImpl_FindDevice
,
1235 IDirectInput8WImpl_EnumDevicesBySemantics
,
1236 IDirectInput8WImpl_ConfigureDevices
1239 static const IDirectInputJoyConfig8Vtbl JoyConfig8vt
=
1241 JoyConfig8Impl_QueryInterface
,
1242 JoyConfig8Impl_AddRef
,
1243 JoyConfig8Impl_Release
,
1244 JoyConfig8Impl_Acquire
,
1245 JoyConfig8Impl_Unacquire
,
1246 JoyConfig8Impl_SetCooperativeLevel
,
1247 JoyConfig8Impl_SendNotify
,
1248 JoyConfig8Impl_EnumTypes
,
1249 JoyConfig8Impl_GetTypeInfo
,
1250 JoyConfig8Impl_SetTypeInfo
,
1251 JoyConfig8Impl_DeleteType
,
1252 JoyConfig8Impl_GetConfig
,
1253 JoyConfig8Impl_SetConfig
,
1254 JoyConfig8Impl_DeleteConfig
,
1255 JoyConfig8Impl_GetUserValues
,
1256 JoyConfig8Impl_SetUserValues
,
1257 JoyConfig8Impl_AddNewHardware
,
1258 JoyConfig8Impl_OpenTypeKey
,
1259 JoyConfig8Impl_OpenAppStatusKey
1262 /*******************************************************************************
1263 * DirectInput ClassFactory
1267 /* IUnknown fields */
1268 IClassFactory IClassFactory_iface
;
1270 } IClassFactoryImpl
;
1272 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
1274 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
1277 static HRESULT WINAPI
DICF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
1278 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1280 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
1281 return E_NOINTERFACE
;
1284 static ULONG WINAPI
DICF_AddRef(LPCLASSFACTORY iface
) {
1285 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1286 return InterlockedIncrement(&(This
->ref
));
1289 static ULONG WINAPI
DICF_Release(LPCLASSFACTORY iface
) {
1290 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1291 /* static class, won't be freed */
1292 return InterlockedDecrement(&(This
->ref
));
1295 static HRESULT WINAPI
DICF_CreateInstance(
1296 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
1298 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1300 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1301 if ( IsEqualGUID( &IID_IUnknown
, riid
) ||
1302 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
1303 IsEqualGUID( &IID_IDirectInputW
, riid
) ||
1304 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
1305 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
1306 IsEqualGUID( &IID_IDirectInput7A
, riid
) ||
1307 IsEqualGUID( &IID_IDirectInput7W
, riid
) ) {
1308 return create_directinput_instance(riid
, ppobj
, NULL
);
1311 FIXME("(%p,%p,%s,%p) Interface not found!\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1312 return E_NOINTERFACE
;
1315 static HRESULT WINAPI
DICF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
1316 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1317 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
1321 static const IClassFactoryVtbl DICF_Vtbl
= {
1322 DICF_QueryInterface
,
1325 DICF_CreateInstance
,
1328 static IClassFactoryImpl DINPUT_CF
= {{&DICF_Vtbl
}, 1 };
1330 /***********************************************************************
1331 * DllCanUnloadNow (DINPUT.@)
1333 HRESULT WINAPI
DllCanUnloadNow(void)
1338 /***********************************************************************
1339 * DllGetClassObject (DINPUT.@)
1341 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1343 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1344 if ( IsEqualCLSID( &IID_IClassFactory
, riid
) ) {
1346 IClassFactory_AddRef((IClassFactory
*)*ppv
);
1350 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1351 return CLASS_E_CLASSNOTAVAILABLE
;
1354 /***********************************************************************
1355 * DllRegisterServer (DINPUT.@)
1357 HRESULT WINAPI
DllRegisterServer(void)
1359 return __wine_register_resources( DINPUT_instance
);
1362 /***********************************************************************
1363 * DllUnregisterServer (DINPUT.@)
1365 HRESULT WINAPI
DllUnregisterServer(void)
1367 return __wine_unregister_resources( DINPUT_instance
);
1370 /******************************************************************************
1371 * DInput hook thread
1374 static LRESULT CALLBACK
LL_hook_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1376 IDirectInputImpl
*dinput
;
1379 if (code
!= HC_ACTION
) return CallNextHookEx( 0, code
, wparam
, lparam
);
1381 EnterCriticalSection( &dinput_hook_crit
);
1382 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1384 IDirectInputDeviceImpl
*dev
;
1386 EnterCriticalSection( &dinput
->crit
);
1387 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1388 if (dev
->acquired
&& dev
->event_proc
)
1390 TRACE("calling %p->%p (%lx %lx)\n", dev
, dev
->event_proc
, wparam
, lparam
);
1391 skip
|= dev
->event_proc( &dev
->IDirectInputDevice8A_iface
, wparam
, lparam
);
1393 LeaveCriticalSection( &dinput
->crit
);
1395 LeaveCriticalSection( &dinput_hook_crit
);
1397 return skip
? 1 : CallNextHookEx( 0, code
, wparam
, lparam
);
1400 static LRESULT CALLBACK
callwndproc_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1402 CWPSTRUCT
*msg
= (CWPSTRUCT
*)lparam
;
1403 IDirectInputImpl
*dinput
;
1406 if (code
!= HC_ACTION
|| (msg
->message
!= WM_KILLFOCUS
&&
1407 msg
->message
!= WM_ACTIVATEAPP
&& msg
->message
!= WM_ACTIVATE
))
1408 return CallNextHookEx( 0, code
, wparam
, lparam
);
1410 foreground
= GetForegroundWindow();
1412 EnterCriticalSection( &dinput_hook_crit
);
1414 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1416 IDirectInputDeviceImpl
*dev
;
1418 EnterCriticalSection( &dinput
->crit
);
1419 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1421 if (!dev
->acquired
) continue;
1423 if (msg
->hwnd
== dev
->win
&& msg
->hwnd
!= foreground
)
1425 TRACE( "%p window is not foreground - unacquiring %p\n", dev
->win
, dev
);
1426 IDirectInputDevice_Unacquire( &dev
->IDirectInputDevice8A_iface
);
1429 LeaveCriticalSection( &dinput
->crit
);
1431 LeaveCriticalSection( &dinput_hook_crit
);
1433 return CallNextHookEx( 0, code
, wparam
, lparam
);
1436 static DWORD WINAPI
hook_thread_proc(void *param
)
1438 static HHOOK kbd_hook
, mouse_hook
;
1441 /* Force creation of the message queue */
1442 PeekMessageW( &msg
, 0, 0, 0, PM_NOREMOVE
);
1443 SetEvent(*(LPHANDLE
)param
);
1445 while (GetMessageW( &msg
, 0, 0, 0 ))
1447 UINT kbd_cnt
= 0, mice_cnt
= 0;
1449 if (msg
.message
== WM_USER
+0x10)
1451 IDirectInputImpl
*dinput
;
1453 TRACE( "Processing hook change notification lp:%ld\n", msg
.lParam
);
1455 if (!msg
.wParam
&& !msg
.lParam
)
1457 if (kbd_hook
) UnhookWindowsHookEx( kbd_hook
);
1458 if (mouse_hook
) UnhookWindowsHookEx( mouse_hook
);
1459 kbd_hook
= mouse_hook
= NULL
;
1463 EnterCriticalSection( &dinput_hook_crit
);
1465 /* Count acquired keyboards and mice*/
1466 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1468 IDirectInputDeviceImpl
*dev
;
1470 EnterCriticalSection( &dinput
->crit
);
1471 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1473 if (!dev
->acquired
|| !dev
->event_proc
) continue;
1475 if (IsEqualGUID( &dev
->guid
, &GUID_SysKeyboard
) ||
1476 IsEqualGUID( &dev
->guid
, &DInput_Wine_Keyboard_GUID
))
1479 if (IsEqualGUID( &dev
->guid
, &GUID_SysMouse
) ||
1480 IsEqualGUID( &dev
->guid
, &DInput_Wine_Mouse_GUID
))
1483 LeaveCriticalSection( &dinput
->crit
);
1485 LeaveCriticalSection( &dinput_hook_crit
);
1487 if (kbd_cnt
&& !kbd_hook
)
1488 kbd_hook
= SetWindowsHookExW( WH_KEYBOARD_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1489 else if (!kbd_cnt
&& kbd_hook
)
1491 UnhookWindowsHookEx( kbd_hook
);
1495 if (mice_cnt
&& !mouse_hook
)
1496 mouse_hook
= SetWindowsHookExW( WH_MOUSE_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1497 else if (!mice_cnt
&& mouse_hook
)
1499 UnhookWindowsHookEx( mouse_hook
);
1503 TranslateMessage(&msg
);
1504 DispatchMessageW(&msg
);
1510 static DWORD hook_thread_id
;
1512 static CRITICAL_SECTION_DEBUG dinput_critsect_debug
=
1514 0, 0, &dinput_hook_crit
,
1515 { &dinput_critsect_debug
.ProcessLocksList
, &dinput_critsect_debug
.ProcessLocksList
},
1516 0, 0, { (DWORD_PTR
)(__FILE__
": dinput_hook_crit") }
1518 static CRITICAL_SECTION dinput_hook_crit
= { &dinput_critsect_debug
, -1, 0, 0, 0, 0 };
1520 static BOOL
check_hook_thread(void)
1522 static HANDLE hook_thread
;
1524 EnterCriticalSection(&dinput_hook_crit
);
1526 TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list
));
1527 if (!list_empty(&direct_input_list
) && !hook_thread
)
1531 event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1532 hook_thread
= CreateThread(NULL
, 0, hook_thread_proc
, &event
, 0, &hook_thread_id
);
1533 if (event
&& hook_thread
)
1537 handles
[1] = hook_thread
;
1538 WaitForMultipleObjects(2, handles
, FALSE
, INFINITE
);
1540 LeaveCriticalSection(&dinput_hook_crit
);
1543 else if (list_empty(&direct_input_list
) && hook_thread
)
1545 DWORD tid
= hook_thread_id
;
1548 PostThreadMessageW(tid
, WM_USER
+0x10, 0, 0);
1549 LeaveCriticalSection(&dinput_hook_crit
);
1551 /* wait for hook thread to exit */
1552 WaitForSingleObject(hook_thread
, INFINITE
);
1553 CloseHandle(hook_thread
);
1557 LeaveCriticalSection(&dinput_hook_crit
);
1559 return hook_thread_id
!= 0;
1562 void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface
)
1564 static HHOOK callwndproc_hook
;
1565 static ULONG foreground_cnt
;
1566 IDirectInputDeviceImpl
*dev
= impl_from_IDirectInputDevice8W(iface
);
1568 EnterCriticalSection(&dinput_hook_crit
);
1570 if (dev
->dwCoopLevel
& DISCL_FOREGROUND
)
1578 if (foreground_cnt
&& !callwndproc_hook
)
1579 callwndproc_hook
= SetWindowsHookExW( WH_CALLWNDPROC
, callwndproc_proc
,
1580 DINPUT_instance
, GetCurrentThreadId() );
1581 else if (!foreground_cnt
&& callwndproc_hook
)
1583 UnhookWindowsHookEx( callwndproc_hook
);
1584 callwndproc_hook
= NULL
;
1587 PostThreadMessageW( hook_thread_id
, WM_USER
+0x10, 1, 0 );
1589 LeaveCriticalSection(&dinput_hook_crit
);
1592 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserv
)
1596 case DLL_PROCESS_ATTACH
:
1597 DisableThreadLibraryCalls(inst
);
1598 DINPUT_instance
= inst
;
1600 case DLL_PROCESS_DETACH
:
1601 DeleteCriticalSection(&dinput_hook_crit
);