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_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
84 return CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
);
87 static const struct dinput_device
*dinput_devices
[] =
91 &joystick_linuxinput_device
,
92 &joystick_linux_device
,
95 #define NB_DINPUT_DEVICES (sizeof(dinput_devices)/sizeof(dinput_devices[0]))
97 static HINSTANCE DINPUT_instance
= NULL
;
99 static BOOL
check_hook_thread(void);
100 static CRITICAL_SECTION dinput_hook_crit
;
101 static struct list direct_input_list
= LIST_INIT( direct_input_list
);
103 static HRESULT
initialize_directinput_instance(IDirectInputImpl
*This
, DWORD dwVersion
);
104 static void uninitialize_directinput_instance(IDirectInputImpl
*This
);
106 static HRESULT
create_directinput_instance(REFIID riid
, LPVOID
*ppDI
, IDirectInputImpl
**out
)
108 IDirectInputImpl
*This
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectInputImpl
) );
112 return E_OUTOFMEMORY
;
114 This
->IDirectInput7A_iface
.lpVtbl
= &ddi7avt
;
115 This
->IDirectInput7W_iface
.lpVtbl
= &ddi7wvt
;
116 This
->IDirectInput8A_iface
.lpVtbl
= &ddi8avt
;
117 This
->IDirectInput8W_iface
.lpVtbl
= &ddi8wvt
;
118 This
->IDirectInputJoyConfig8_iface
.lpVtbl
= &JoyConfig8vt
;
120 hr
= IDirectInput_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppDI
);
123 HeapFree( GetProcessHeap(), 0, This
);
127 if (out
) *out
= This
;
131 /******************************************************************************
132 * DirectInputCreateEx (DINPUT.@)
134 HRESULT WINAPI
DirectInputCreateEx(
135 HINSTANCE hinst
, DWORD dwVersion
, REFIID riid
, LPVOID
*ppDI
,
138 IDirectInputImpl
*This
;
141 TRACE("(%p,%04x,%s,%p,%p)\n", hinst
, dwVersion
, debugstr_guid(riid
), ppDI
, punkOuter
);
143 if (IsEqualGUID( &IID_IDirectInputA
, riid
) ||
144 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
145 IsEqualGUID( &IID_IDirectInput7A
, riid
) ||
146 IsEqualGUID( &IID_IDirectInputW
, riid
) ||
147 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
148 IsEqualGUID( &IID_IDirectInput7W
, riid
))
150 hr
= create_directinput_instance(riid
, ppDI
, &This
);
155 return DIERR_NOINTERFACE
;
157 hr
= IDirectInput_Initialize( &This
->IDirectInput7A_iface
, hinst
, dwVersion
);
160 IDirectInput_Release( &This
->IDirectInput7A_iface
);
168 /******************************************************************************
169 * DirectInputCreateA (DINPUT.@)
171 HRESULT WINAPI DECLSPEC_HOTPATCH
DirectInputCreateA(HINSTANCE hinst
, DWORD dwVersion
, LPDIRECTINPUTA
*ppDI
, LPUNKNOWN punkOuter
)
173 return DirectInputCreateEx(hinst
, dwVersion
, &IID_IDirectInput7A
, (LPVOID
*)ppDI
, punkOuter
);
176 /******************************************************************************
177 * DirectInputCreateW (DINPUT.@)
179 HRESULT WINAPI DECLSPEC_HOTPATCH
DirectInputCreateW(HINSTANCE hinst
, DWORD dwVersion
, LPDIRECTINPUTW
*ppDI
, LPUNKNOWN punkOuter
)
181 return DirectInputCreateEx(hinst
, dwVersion
, &IID_IDirectInput7W
, (LPVOID
*)ppDI
, punkOuter
);
184 static const char *_dump_DIDEVTYPE_value(DWORD dwDevType
, DWORD dwVersion
)
186 if (dwVersion
< 0x0800) {
188 case 0: return "All devices";
189 case DIDEVTYPE_MOUSE
: return "DIDEVTYPE_MOUSE";
190 case DIDEVTYPE_KEYBOARD
: return "DIDEVTYPE_KEYBOARD";
191 case DIDEVTYPE_JOYSTICK
: return "DIDEVTYPE_JOYSTICK";
192 case DIDEVTYPE_DEVICE
: return "DIDEVTYPE_DEVICE";
193 default: return "Unknown";
197 case DI8DEVCLASS_ALL
: return "All devices";
198 case DI8DEVCLASS_POINTER
: return "DI8DEVCLASS_POINTER";
199 case DI8DEVCLASS_KEYBOARD
: return "DI8DEVCLASS_KEYBOARD";
200 case DI8DEVCLASS_DEVICE
: return "DI8DEVCLASS_DEVICE";
201 case DI8DEVCLASS_GAMECTRL
: return "DI8DEVCLASS_GAMECTRL";
202 default: return "Unknown";
207 static void _dump_EnumDevices_dwFlags(DWORD dwFlags
)
209 if (TRACE_ON(dinput
)) {
211 static const struct {
215 #define FE(x) { x, #x}
216 FE(DIEDFL_ALLDEVICES
),
217 FE(DIEDFL_ATTACHEDONLY
),
218 FE(DIEDFL_FORCEFEEDBACK
),
219 FE(DIEDFL_INCLUDEALIASES
),
220 FE(DIEDFL_INCLUDEPHANTOMS
),
221 FE(DIEDFL_INCLUDEHIDDEN
)
226 TRACE("DIEDFL_ALLDEVICES\n");
229 for (i
= 0; i
< (sizeof(flags
) / sizeof(flags
[0])); i
++)
230 if (flags
[i
].mask
& dwFlags
)
231 TRACE("%s ",flags
[i
].name
);
236 static void _dump_diactionformatA(LPDIACTIONFORMATA lpdiActionFormat
)
240 TRACE("diaf.dwSize = %d\n", lpdiActionFormat
->dwSize
);
241 TRACE("diaf.dwActionSize = %d\n", lpdiActionFormat
->dwActionSize
);
242 TRACE("diaf.dwDataSize = %d\n", lpdiActionFormat
->dwDataSize
);
243 TRACE("diaf.dwNumActions = %d\n", lpdiActionFormat
->dwNumActions
);
244 TRACE("diaf.rgoAction = %p\n", lpdiActionFormat
->rgoAction
);
245 TRACE("diaf.guidActionMap = %s\n", debugstr_guid(&lpdiActionFormat
->guidActionMap
));
246 TRACE("diaf.dwGenre = 0x%08x\n", lpdiActionFormat
->dwGenre
);
247 TRACE("diaf.dwBufferSize = %d\n", lpdiActionFormat
->dwBufferSize
);
248 TRACE("diaf.lAxisMin = %d\n", lpdiActionFormat
->lAxisMin
);
249 TRACE("diaf.lAxisMax = %d\n", lpdiActionFormat
->lAxisMax
);
250 TRACE("diaf.hInstString = %p\n", lpdiActionFormat
->hInstString
);
251 TRACE("diaf.ftTimeStamp ...\n");
252 TRACE("diaf.dwCRC = 0x%x\n", lpdiActionFormat
->dwCRC
);
253 TRACE("diaf.tszActionMap = %s\n", debugstr_a(lpdiActionFormat
->tszActionMap
));
254 for (i
= 0; i
< lpdiActionFormat
->dwNumActions
; i
++)
256 TRACE("diaf.rgoAction[%u]:\n", i
);
257 TRACE("\tuAppData=0x%lx\n", lpdiActionFormat
->rgoAction
[i
].uAppData
);
258 TRACE("\tdwSemantic=0x%08x\n", lpdiActionFormat
->rgoAction
[i
].dwSemantic
);
259 TRACE("\tdwFlags=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwFlags
);
260 TRACE("\tszActionName=%s\n", debugstr_a(lpdiActionFormat
->rgoAction
[i
].u
.lptszActionName
));
261 TRACE("\tguidInstance=%s\n", debugstr_guid(&lpdiActionFormat
->rgoAction
[i
].guidInstance
));
262 TRACE("\tdwObjID=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwObjID
);
263 TRACE("\tdwHow=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwHow
);
267 void _copy_diactionformatAtoW(LPDIACTIONFORMATW to
, LPDIACTIONFORMATA from
)
271 to
->dwSize
= sizeof(DIACTIONFORMATW
);
272 to
->dwActionSize
= sizeof(DIACTIONW
);
273 to
->dwDataSize
= from
->dwDataSize
;
274 to
->dwNumActions
= from
->dwNumActions
;
275 to
->guidActionMap
= from
->guidActionMap
;
276 to
->dwGenre
= from
->dwGenre
;
277 to
->dwBufferSize
= from
->dwBufferSize
;
278 to
->lAxisMin
= from
->lAxisMin
;
279 to
->lAxisMax
= from
->lAxisMax
;
280 to
->dwCRC
= from
->dwCRC
;
281 to
->ftTimeStamp
= from
->ftTimeStamp
;
283 for (i
=0; i
< to
->dwNumActions
; i
++)
285 to
->rgoAction
[i
].uAppData
= from
->rgoAction
[i
].uAppData
;
286 to
->rgoAction
[i
].dwSemantic
= from
->rgoAction
[i
].dwSemantic
;
287 to
->rgoAction
[i
].dwFlags
= from
->rgoAction
[i
].dwFlags
;
288 to
->rgoAction
[i
].guidInstance
= from
->rgoAction
[i
].guidInstance
;
289 to
->rgoAction
[i
].dwObjID
= from
->rgoAction
[i
].dwObjID
;
290 to
->rgoAction
[i
].dwHow
= from
->rgoAction
[i
].dwHow
;
294 void _copy_diactionformatWtoA(LPDIACTIONFORMATA to
, LPDIACTIONFORMATW from
)
298 to
->dwSize
= sizeof(DIACTIONFORMATA
);
299 to
->dwActionSize
= sizeof(DIACTIONA
);
300 to
->dwDataSize
= from
->dwDataSize
;
301 to
->dwNumActions
= from
->dwNumActions
;
302 to
->guidActionMap
= from
->guidActionMap
;
303 to
->dwGenre
= from
->dwGenre
;
304 to
->dwBufferSize
= from
->dwBufferSize
;
305 to
->lAxisMin
= from
->lAxisMin
;
306 to
->lAxisMax
= from
->lAxisMax
;
307 to
->dwCRC
= from
->dwCRC
;
308 to
->ftTimeStamp
= from
->ftTimeStamp
;
310 for (i
=0; i
< to
->dwNumActions
; i
++)
312 to
->rgoAction
[i
].uAppData
= from
->rgoAction
[i
].uAppData
;
313 to
->rgoAction
[i
].dwSemantic
= from
->rgoAction
[i
].dwSemantic
;
314 to
->rgoAction
[i
].dwFlags
= from
->rgoAction
[i
].dwFlags
;
315 to
->rgoAction
[i
].guidInstance
= from
->rgoAction
[i
].guidInstance
;
316 to
->rgoAction
[i
].dwObjID
= from
->rgoAction
[i
].dwObjID
;
317 to
->rgoAction
[i
].dwHow
= from
->rgoAction
[i
].dwHow
;
321 /* diactionformat_priority
323 * Given a DIACTIONFORMAT structure and a DI genre, returns the enumeration
324 * priority. Joysticks should pass the game genre, and mouse or keyboard their
325 * respective DI*_MASK
327 static DWORD
diactionformat_priorityA(LPDIACTIONFORMATA lpdiaf
, DWORD genre
)
330 DWORD priorityFlags
= 0;
332 /* If there's at least one action for the device it's priority 1 */
333 for(i
=0; i
< lpdiaf
->dwNumActions
; i
++)
334 if ((lpdiaf
->rgoAction
[i
].dwSemantic
& genre
) == genre
)
335 priorityFlags
|= DIEDBS_MAPPEDPRI1
;
337 return priorityFlags
;
340 static DWORD
diactionformat_priorityW(LPDIACTIONFORMATW lpdiaf
, DWORD genre
)
343 DWORD priorityFlags
= 0;
345 /* If there's at least one action for the device it's priority 1 */
346 for(i
=0; i
< lpdiaf
->dwNumActions
; i
++)
347 if ((lpdiaf
->rgoAction
[i
].dwSemantic
& genre
) == genre
)
348 priorityFlags
|= DIEDBS_MAPPEDPRI1
;
350 return priorityFlags
;
353 #if defined __i386__ && defined _MSC_VER
354 __declspec(naked
) BOOL
enum_callback_wrapper(void *callback
, const void *instance
, void *ref
)
367 #elif defined __i386__ && defined __GNUC__
368 extern BOOL
enum_callback_wrapper(void *callback
, const void *instance
, void *ref
);
369 __ASM_GLOBAL_FUNC( enum_callback_wrapper
,
371 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
372 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
374 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
379 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
380 __ASM_CFI(".cfi_same_value %ebp\n\t")
383 #define enum_callback_wrapper(callback, instance, ref) (callback)((instance), (ref))
386 /******************************************************************************
387 * IDirectInputA_EnumDevices
389 static HRESULT WINAPI
IDirectInputAImpl_EnumDevices(
390 LPDIRECTINPUT7A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
391 LPVOID pvRef
, DWORD dwFlags
)
393 IDirectInputImpl
*This
= impl_from_IDirectInput7A(iface
);
394 DIDEVICEINSTANCEA devInstance
;
399 TRACE("(this=%p,0x%04x '%s',%p,%p,0x%04x)\n",
400 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
, This
->dwVersion
),
401 lpCallback
, pvRef
, dwFlags
);
402 _dump_EnumDevices_dwFlags(dwFlags
);
405 dwFlags
& ~(DIEDFL_ATTACHEDONLY
| DIEDFL_FORCEFEEDBACK
| DIEDFL_INCLUDEALIASES
| DIEDFL_INCLUDEPHANTOMS
| DIEDFL_INCLUDEHIDDEN
) ||
406 (dwDevType
> DI8DEVCLASS_GAMECTRL
&& dwDevType
< DI8DEVTYPE_DEVICE
) || dwDevType
> DI8DEVTYPE_SUPPLEMENTAL
)
407 return DIERR_INVALIDPARAM
;
409 if (!This
->initialized
)
410 return DIERR_NOTINITIALIZED
;
412 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
413 if (!dinput_devices
[i
]->enum_deviceA
) continue;
414 for (j
= 0, r
= S_OK
; SUCCEEDED(r
); j
++) {
415 devInstance
.dwSize
= sizeof(devInstance
);
416 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
417 r
= dinput_devices
[i
]->enum_deviceA(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
);
419 if (enum_callback_wrapper(lpCallback
, &devInstance
, pvRef
) == DIENUM_STOP
)
426 /******************************************************************************
427 * IDirectInputW_EnumDevices
429 static HRESULT WINAPI
IDirectInputWImpl_EnumDevices(
430 LPDIRECTINPUT7W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
431 LPVOID pvRef
, DWORD dwFlags
)
433 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
434 DIDEVICEINSTANCEW devInstance
;
439 TRACE("(this=%p,0x%04x '%s',%p,%p,0x%04x)\n",
440 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
, This
->dwVersion
),
441 lpCallback
, pvRef
, dwFlags
);
442 _dump_EnumDevices_dwFlags(dwFlags
);
445 dwFlags
& ~(DIEDFL_ATTACHEDONLY
| DIEDFL_FORCEFEEDBACK
| DIEDFL_INCLUDEALIASES
| DIEDFL_INCLUDEPHANTOMS
| DIEDFL_INCLUDEHIDDEN
) ||
446 (dwDevType
> DI8DEVCLASS_GAMECTRL
&& dwDevType
< DI8DEVTYPE_DEVICE
) || dwDevType
> DI8DEVTYPE_SUPPLEMENTAL
)
447 return DIERR_INVALIDPARAM
;
449 if (!This
->initialized
)
450 return DIERR_NOTINITIALIZED
;
452 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
453 if (!dinput_devices
[i
]->enum_deviceW
) continue;
454 for (j
= 0, r
= S_OK
; SUCCEEDED(r
); j
++) {
455 devInstance
.dwSize
= sizeof(devInstance
);
456 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
457 r
= dinput_devices
[i
]->enum_deviceW(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
);
459 if (enum_callback_wrapper(lpCallback
, &devInstance
, pvRef
) == DIENUM_STOP
)
467 static ULONG WINAPI
IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface
)
469 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
470 ULONG ref
= InterlockedIncrement(&This
->ref
);
472 TRACE( "(%p) incrementing from %d\n", This
, ref
- 1);
476 static ULONG WINAPI
IDirectInputWImpl_AddRef(LPDIRECTINPUT7W iface
)
478 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
479 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
482 static ULONG WINAPI
IDirectInputAImpl_Release(LPDIRECTINPUT7A iface
)
484 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
485 ULONG ref
= InterlockedDecrement( &This
->ref
);
487 TRACE( "(%p) releasing from %d\n", This
, ref
+ 1 );
491 uninitialize_directinput_instance( This
);
492 HeapFree( GetProcessHeap(), 0, This
);
498 static ULONG WINAPI
IDirectInputWImpl_Release(LPDIRECTINPUT7W iface
)
500 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
501 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
504 static HRESULT WINAPI
IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface
, REFIID riid
, LPVOID
*ppobj
)
506 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
508 TRACE( "(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
513 if (IsEqualGUID( &IID_IUnknown
, riid
) ||
514 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
515 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
516 IsEqualGUID( &IID_IDirectInput7A
, riid
))
518 *ppobj
= &This
->IDirectInput7A_iface
;
519 IUnknown_AddRef( (IUnknown
*)*ppobj
);
524 if (IsEqualGUID( &IID_IDirectInputW
, riid
) ||
525 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
526 IsEqualGUID( &IID_IDirectInput7W
, riid
))
528 *ppobj
= &This
->IDirectInput7W_iface
;
529 IUnknown_AddRef( (IUnknown
*)*ppobj
);
534 if (IsEqualGUID( &IID_IDirectInput8A
, riid
))
536 *ppobj
= &This
->IDirectInput8A_iface
;
537 IUnknown_AddRef( (IUnknown
*)*ppobj
);
542 if (IsEqualGUID( &IID_IDirectInput8W
, riid
))
544 *ppobj
= &This
->IDirectInput8W_iface
;
545 IUnknown_AddRef( (IUnknown
*)*ppobj
);
550 if (IsEqualGUID( &IID_IDirectInputJoyConfig8
, riid
))
552 *ppobj
= &This
->IDirectInputJoyConfig8_iface
;
553 IUnknown_AddRef( (IUnknown
*)*ppobj
);
558 FIXME( "Unsupported interface: %s\n", debugstr_guid(riid
));
560 return E_NOINTERFACE
;
563 static HRESULT WINAPI
IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface
, REFIID riid
, LPVOID
*ppobj
)
565 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
566 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
569 static HRESULT
initialize_directinput_instance(IDirectInputImpl
*This
, DWORD dwVersion
)
571 if (!This
->initialized
)
573 This
->dwVersion
= dwVersion
;
574 This
->evsequence
= 1;
576 InitializeCriticalSection( &This
->crit
);
577 This
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IDirectInputImpl*->crit");
579 list_init( &This
->devices_list
);
581 /* Add self to the list of the IDirectInputs */
582 EnterCriticalSection( &dinput_hook_crit
);
583 list_add_head( &direct_input_list
, &This
->entry
);
584 LeaveCriticalSection( &dinput_hook_crit
);
586 This
->initialized
= TRUE
;
588 if (!check_hook_thread())
590 uninitialize_directinput_instance( This
);
591 return DIERR_GENERIC
;
598 static void uninitialize_directinput_instance(IDirectInputImpl
*This
)
600 if (This
->initialized
)
602 /* Remove self from the list of the IDirectInputs */
603 EnterCriticalSection( &dinput_hook_crit
);
604 list_remove( &This
->entry
);
605 LeaveCriticalSection( &dinput_hook_crit
);
609 This
->crit
.DebugInfo
->Spare
[0] = 0;
610 DeleteCriticalSection( &This
->crit
);
612 This
->initialized
= FALSE
;
616 enum directinput_versions
618 DIRECTINPUT_VERSION_300
= 0x0300,
619 DIRECTINPUT_VERSION_500
= 0x0500,
620 DIRECTINPUT_VERSION_50A
= 0x050A,
621 DIRECTINPUT_VERSION_5B2
= 0x05B2,
622 DIRECTINPUT_VERSION_602
= 0x0602,
623 DIRECTINPUT_VERSION_61A
= 0x061A,
624 DIRECTINPUT_VERSION_700
= 0x0700,
627 static HRESULT WINAPI
IDirectInputAImpl_Initialize(LPDIRECTINPUT7A iface
, HINSTANCE hinst
, DWORD version
)
629 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
631 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
634 return DIERR_INVALIDPARAM
;
635 else if (version
== 0)
636 return DIERR_NOTINITIALIZED
;
637 else if (version
> DIRECTINPUT_VERSION_700
)
638 return DIERR_OLDDIRECTINPUTVERSION
;
639 else if (version
!= DIRECTINPUT_VERSION_300
&& version
!= DIRECTINPUT_VERSION_500
&&
640 version
!= DIRECTINPUT_VERSION_50A
&& version
!= DIRECTINPUT_VERSION_5B2
&&
641 version
!= DIRECTINPUT_VERSION_602
&& version
!= DIRECTINPUT_VERSION_61A
&&
642 version
!= DIRECTINPUT_VERSION_700
&& version
!= DIRECTINPUT_VERSION
)
643 return DIERR_BETADIRECTINPUTVERSION
;
645 return initialize_directinput_instance(This
, version
);
648 static HRESULT WINAPI
IDirectInputWImpl_Initialize(LPDIRECTINPUT7W iface
, HINSTANCE hinst
, DWORD x
)
650 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
651 return IDirectInputAImpl_Initialize( &This
->IDirectInput7A_iface
, hinst
, x
);
654 static HRESULT WINAPI
IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface
, REFGUID rguid
)
656 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
658 LPDIRECTINPUTDEVICEA device
;
660 TRACE( "(%p)->(%s)\n", This
, debugstr_guid(rguid
) );
662 if (!rguid
) return E_POINTER
;
663 if (!This
->initialized
)
664 return DIERR_NOTINITIALIZED
;
666 hr
= IDirectInput_CreateDevice( iface
, rguid
, &device
, NULL
);
667 if (hr
!= DI_OK
) return DI_NOTATTACHED
;
669 IUnknown_Release( device
);
674 static HRESULT WINAPI
IDirectInputWImpl_GetDeviceStatus(LPDIRECTINPUT7W iface
, REFGUID rguid
)
676 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
677 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
680 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface
,
684 WCHAR control_exeW
[] = {'c','o','n','t','r','o','l','.','e','x','e',0};
685 STARTUPINFOW si
= {0};
686 PROCESS_INFORMATION pi
;
688 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
690 TRACE( "(%p)->(%p, %08x)\n", This
, hwndOwner
, dwFlags
);
692 if (hwndOwner
&& !IsWindow(hwndOwner
))
696 return DIERR_INVALIDPARAM
;
698 if (!This
->initialized
)
699 return DIERR_NOTINITIALIZED
;
701 if (!CreateProcessW(NULL
, control_exeW
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
))
702 return HRESULT_FROM_WIN32(GetLastError());
707 static HRESULT WINAPI
IDirectInputWImpl_RunControlPanel(LPDIRECTINPUT7W iface
, HWND hwndOwner
, DWORD dwFlags
)
709 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
710 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
713 static HRESULT WINAPI
IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
714 LPCSTR pszName
, LPGUID pguidInstance
)
716 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
718 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), pszName
, pguidInstance
);
723 static HRESULT WINAPI
IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
724 LPCWSTR pszName
, LPGUID pguidInstance
)
726 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
728 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), debugstr_w(pszName
), pguidInstance
);
733 static HRESULT
create_device(IDirectInputImpl
*This
, REFGUID rguid
, REFIID riid
, LPVOID
*pvOut
, BOOL unicode
)
740 if (!rguid
|| !pvOut
)
743 if (!This
->initialized
)
744 return DIERR_NOTINITIALIZED
;
746 /* Loop on all the devices to see if anyone matches the given GUID */
747 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
751 if (!dinput_devices
[i
]->create_device
) continue;
752 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, riid
, pvOut
, unicode
)) == DI_OK
)
756 WARN("invalid device GUID %s\n", debugstr_guid(rguid
));
757 return DIERR_DEVICENOTREG
;
760 static HRESULT WINAPI
IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface
, REFGUID rguid
,
761 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
763 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
765 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
767 return create_device(This
, rguid
, riid
, pvOut
, FALSE
);
770 static HRESULT WINAPI
IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface
, REFGUID rguid
,
771 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
773 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
775 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
777 return create_device(This
, rguid
, riid
, pvOut
, TRUE
);
780 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
781 LPDIRECTINPUTDEVICEA
* pdev
, LPUNKNOWN punk
)
783 return IDirectInput7AImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
786 static HRESULT WINAPI
IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
787 LPDIRECTINPUTDEVICEW
* pdev
, LPUNKNOWN punk
)
789 return IDirectInput7WImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
792 /*******************************************************************************
796 static ULONG WINAPI
IDirectInput8AImpl_AddRef(LPDIRECTINPUT8A iface
)
798 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
799 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
802 static ULONG WINAPI
IDirectInput8WImpl_AddRef(LPDIRECTINPUT8W iface
)
804 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
805 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
808 static HRESULT WINAPI
IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface
, REFIID riid
, LPVOID
*ppobj
)
810 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
811 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
814 static HRESULT WINAPI
IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W iface
, REFIID riid
, LPVOID
*ppobj
)
816 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
817 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
820 static ULONG WINAPI
IDirectInput8AImpl_Release(LPDIRECTINPUT8A iface
)
822 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
823 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
826 static ULONG WINAPI
IDirectInput8WImpl_Release(LPDIRECTINPUT8W iface
)
828 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
829 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
832 static HRESULT WINAPI
IDirectInput8AImpl_CreateDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
,
833 LPDIRECTINPUTDEVICE8A
* pdev
, LPUNKNOWN punk
)
835 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
836 return IDirectInput7AImpl_CreateDeviceEx( &This
->IDirectInput7A_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
839 static HRESULT WINAPI
IDirectInput8WImpl_CreateDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
,
840 LPDIRECTINPUTDEVICE8W
* pdev
, LPUNKNOWN punk
)
842 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
843 return IDirectInput7WImpl_CreateDeviceEx( &This
->IDirectInput7W_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
846 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevices(LPDIRECTINPUT8A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
847 LPVOID pvRef
, DWORD dwFlags
)
849 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
850 return IDirectInputAImpl_EnumDevices( &This
->IDirectInput7A_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
853 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
854 LPVOID pvRef
, DWORD dwFlags
)
856 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
857 return IDirectInputWImpl_EnumDevices( &This
->IDirectInput7W_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
860 static HRESULT WINAPI
IDirectInput8AImpl_GetDeviceStatus(LPDIRECTINPUT8A iface
, REFGUID rguid
)
862 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
863 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
866 static HRESULT WINAPI
IDirectInput8WImpl_GetDeviceStatus(LPDIRECTINPUT8W iface
, REFGUID rguid
)
868 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
869 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
872 static HRESULT WINAPI
IDirectInput8AImpl_RunControlPanel(LPDIRECTINPUT8A iface
, HWND hwndOwner
, DWORD dwFlags
)
874 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
875 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
878 static HRESULT WINAPI
IDirectInput8WImpl_RunControlPanel(LPDIRECTINPUT8W iface
, HWND hwndOwner
, DWORD dwFlags
)
880 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
881 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
884 static HRESULT WINAPI
IDirectInput8AImpl_Initialize(LPDIRECTINPUT8A iface
, HINSTANCE hinst
, DWORD version
)
886 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
888 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
891 return DIERR_INVALIDPARAM
;
892 else if (version
== 0)
893 return DIERR_NOTINITIALIZED
;
894 else if (version
< DIRECTINPUT_VERSION
)
895 return DIERR_BETADIRECTINPUTVERSION
;
896 else if (version
> DIRECTINPUT_VERSION
)
897 return DIERR_OLDDIRECTINPUTVERSION
;
899 return initialize_directinput_instance(This
, version
);
902 static HRESULT WINAPI
IDirectInput8WImpl_Initialize(LPDIRECTINPUT8W iface
, HINSTANCE hinst
, DWORD version
)
904 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
905 return IDirectInput8AImpl_Initialize( &This
->IDirectInput8A_iface
, hinst
, version
);
908 static HRESULT WINAPI
IDirectInput8AImpl_FindDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
, LPCSTR pszName
, LPGUID pguidInstance
)
910 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
911 return IDirectInput2AImpl_FindDevice( &This
->IDirectInput7A_iface
, rguid
, pszName
, pguidInstance
);
914 static HRESULT WINAPI
IDirectInput8WImpl_FindDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
, LPCWSTR pszName
, LPGUID pguidInstance
)
916 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
917 return IDirectInput2WImpl_FindDevice( &This
->IDirectInput7W_iface
, rguid
, pszName
, pguidInstance
);
920 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevicesBySemantics(
921 LPDIRECTINPUT8A iface
, LPCSTR ptszUserName
, LPDIACTIONFORMATA lpdiActionFormat
,
922 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback
,
923 LPVOID pvRef
, DWORD dwFlags
926 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
927 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
928 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
929 DIDEVICEINSTANCEA didevi
;
930 LPDIRECTINPUTDEVICE8A lpdid
;
935 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_a(ptszUserName
), lpdiActionFormat
,
936 lpCallback
, pvRef
, dwFlags
);
937 #define X(x) if (dwFlags & x) FIXME("\tdwFlags |= "#x"\n");
938 X(DIEDBSFL_ATTACHEDONLY
)
940 X(DIEDBSFL_FORCEFEEDBACK
)
941 X(DIEDBSFL_AVAILABLEDEVICES
)
942 X(DIEDBSFL_MULTIMICEKEYBOARDS
)
943 X(DIEDBSFL_NONGAMINGDEVICES
)
946 _dump_diactionformatA(lpdiActionFormat
);
948 didevi
.dwSize
= sizeof(didevi
);
950 /* Enumerate all the joysticks */
951 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
955 if (!dinput_devices
[i
]->enum_deviceA
) continue;
957 for (j
= 0, enumSuccess
= S_OK
; SUCCEEDED(enumSuccess
); j
++)
959 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
961 callbackFlags
= diactionformat_priorityA(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
962 /* Default behavior is to enumerate attached game controllers */
963 enumSuccess
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
964 if (enumSuccess
== S_OK
)
966 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
968 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
974 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
976 /* Enumerate keyboard and mouse */
977 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
979 callbackFlags
= diactionformat_priorityA(lpdiActionFormat
, actionMasks
[i
]);
981 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
982 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
984 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
991 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevicesBySemantics(
992 LPDIRECTINPUT8W iface
, LPCWSTR ptszUserName
, LPDIACTIONFORMATW lpdiActionFormat
,
993 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback
,
994 LPVOID pvRef
, DWORD dwFlags
997 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
998 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
999 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
1000 DIDEVICEINSTANCEW didevi
;
1001 LPDIRECTINPUTDEVICE8W lpdid
;
1002 DWORD callbackFlags
;
1005 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_w(ptszUserName
), lpdiActionFormat
,
1006 lpCallback
, pvRef
, dwFlags
);
1008 didevi
.dwSize
= sizeof(didevi
);
1010 /* Enumerate all the joysticks */
1011 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
1013 HRESULT enumSuccess
;
1015 if (!dinput_devices
[i
]->enum_deviceW
) continue;
1017 for (j
= 0, enumSuccess
= S_OK
; SUCCEEDED(enumSuccess
); j
++)
1019 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
1021 callbackFlags
= diactionformat_priorityW(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
1022 /* Default behavior is to enumerate attached game controllers */
1023 enumSuccess
= dinput_devices
[i
]->enum_deviceW(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
1024 if (enumSuccess
== S_OK
)
1026 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
1028 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
1034 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
1036 /* Enumerate keyboard and mouse */
1037 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
1039 callbackFlags
= diactionformat_priorityW(lpdiActionFormat
, actionMasks
[i
]);
1041 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
1042 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
1044 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
1051 static HRESULT WINAPI
IDirectInput8WImpl_ConfigureDevices(
1052 LPDIRECTINPUT8W iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1053 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1056 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
1058 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1060 /* Call helper function in config.c to do the real work */
1061 return _configure_devices(iface
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1064 static HRESULT WINAPI
IDirectInput8AImpl_ConfigureDevices(
1065 LPDIRECTINPUT8A iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1066 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1069 IDirectInputImpl
*This
= impl_from_IDirectInput8A(iface
);
1070 DIACTIONFORMATW diafW
;
1071 DICONFIGUREDEVICESPARAMSW diCDParamsW
;
1075 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1077 /* Copy parameters */
1078 diCDParamsW
.dwSize
= sizeof(DICONFIGUREDEVICESPARAMSW
);
1079 diCDParamsW
.dwcFormats
= lpdiCDParams
->dwcFormats
;
1080 diCDParamsW
.lprgFormats
= &diafW
;
1081 diCDParamsW
.hwnd
= lpdiCDParams
->hwnd
;
1083 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiCDParams
->lprgFormats
->dwNumActions
);
1084 _copy_diactionformatAtoW(&diafW
, lpdiCDParams
->lprgFormats
);
1086 /* Copy action names */
1087 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1089 const char* from
= lpdiCDParams
->lprgFormats
->rgoAction
[i
].u
.lptszActionName
;
1090 int len
= MultiByteToWideChar(CP_ACP
, 0, from
, -1, NULL
, 0);
1091 WCHAR
*to
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*len
);
1093 MultiByteToWideChar(CP_ACP
, 0, from
, -1, to
, len
);
1094 diafW
.rgoAction
[i
].u
.lptszActionName
= to
;
1097 hr
= IDirectInput8WImpl_ConfigureDevices(&This
->IDirectInput8W_iface
, lpdiCallback
, &diCDParamsW
, dwFlags
, pvRefData
);
1099 /* Copy back configuration */
1101 _copy_diactionformatWtoA(lpdiCDParams
->lprgFormats
, &diafW
);
1104 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1105 HeapFree(GetProcessHeap(), 0, (void*) diafW
.rgoAction
[i
].u
.lptszActionName
);
1107 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
1112 /*****************************************************************************
1113 * IDirectInputJoyConfig8 interface
1116 static inline IDirectInputImpl
*impl_from_IDirectInputJoyConfig8(IDirectInputJoyConfig8
*iface
)
1118 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInputJoyConfig8_iface
);
1121 static HRESULT WINAPI
JoyConfig8Impl_QueryInterface(IDirectInputJoyConfig8
*iface
, REFIID riid
, void** ppobj
)
1123 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1124 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
1127 static ULONG WINAPI
JoyConfig8Impl_AddRef(IDirectInputJoyConfig8
*iface
)
1129 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1130 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
1133 static ULONG WINAPI
JoyConfig8Impl_Release(IDirectInputJoyConfig8
*iface
)
1135 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1136 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
1139 static HRESULT WINAPI
JoyConfig8Impl_Acquire(IDirectInputJoyConfig8
*iface
)
1141 FIXME( "(%p): stub!\n", iface
);
1145 static HRESULT WINAPI
JoyConfig8Impl_Unacquire(IDirectInputJoyConfig8
*iface
)
1147 FIXME( "(%p): stub!\n", iface
);
1151 static HRESULT WINAPI
JoyConfig8Impl_SetCooperativeLevel(IDirectInputJoyConfig8
*iface
, HWND hwnd
, DWORD flags
)
1153 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, hwnd
, flags
);
1157 static HRESULT WINAPI
JoyConfig8Impl_SendNotify(IDirectInputJoyConfig8
*iface
)
1159 FIXME( "(%p): stub!\n", iface
);
1163 static HRESULT WINAPI
JoyConfig8Impl_EnumTypes(IDirectInputJoyConfig8
*iface
, LPDIJOYTYPECALLBACK cb
, void *ref
)
1165 FIXME( "(%p)->(%p, %p): stub!\n", iface
, cb
, ref
);
1169 static HRESULT WINAPI
JoyConfig8Impl_GetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPDIJOYTYPEINFO info
, DWORD flags
)
1171 FIXME( "(%p)->(%s, %p, 0x%08x): stub!\n", iface
, debugstr_w(name
), info
, flags
);
1175 static HRESULT WINAPI
JoyConfig8Impl_SetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPCDIJOYTYPEINFO info
, DWORD flags
,
1178 FIXME( "(%p)->(%s, %p, 0x%08x, %s): stub!\n", iface
, debugstr_w(name
), info
, flags
, debugstr_w(new_name
) );
1182 static HRESULT WINAPI
JoyConfig8Impl_DeleteType(IDirectInputJoyConfig8
*iface
, LPCWSTR name
)
1184 FIXME( "(%p)->(%s): stub!\n", iface
, debugstr_w(name
) );
1188 static HRESULT WINAPI
JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPDIJOYCONFIG info
, DWORD flags
)
1190 IDirectInputImpl
*di
= impl_from_IDirectInputJoyConfig8(iface
);
1195 FIXME("(%p)->(%d, %p, 0x%08x): semi-stub!\n", iface
, id
, info
, flags
);
1197 #define X(x) if (flags & x) FIXME("\tflags |= "#x"\n");
1198 X(DIJC_GUIDINSTANCE
)
1199 X(DIJC_REGHWCONFIGTYPE
)
1204 /* Enumerate all joysticks in order */
1205 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
1207 if (!dinput_devices
[i
]->enum_deviceA
) continue;
1209 for (j
= 0, r
= S_OK
; SUCCEEDED(r
); j
++)
1211 DIDEVICEINSTANCEA dev
;
1212 dev
.dwSize
= sizeof(dev
);
1213 if ((r
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, 0, &dev
, di
->dwVersion
, j
)) == S_OK
)
1215 /* Only take into account the chosen id */
1218 if (flags
& DIJC_GUIDINSTANCE
)
1219 info
->guidInstance
= dev
.guidInstance
;
1228 return DIERR_NOMOREITEMS
;
1231 static HRESULT WINAPI
JoyConfig8Impl_SetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPCDIJOYCONFIG info
, DWORD flags
)
1233 FIXME( "(%p)->(%d, %p, 0x%08x): stub!\n", iface
, id
, info
, flags
);
1237 static HRESULT WINAPI
JoyConfig8Impl_DeleteConfig(IDirectInputJoyConfig8
*iface
, UINT id
)
1239 FIXME( "(%p)->(%d): stub!\n", iface
, id
);
1243 static HRESULT WINAPI
JoyConfig8Impl_GetUserValues(IDirectInputJoyConfig8
*iface
, LPDIJOYUSERVALUES info
, DWORD flags
)
1245 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1249 static HRESULT WINAPI
JoyConfig8Impl_SetUserValues(IDirectInputJoyConfig8
*iface
, LPCDIJOYUSERVALUES info
, DWORD flags
)
1251 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1255 static HRESULT WINAPI
JoyConfig8Impl_AddNewHardware(IDirectInputJoyConfig8
*iface
, HWND hwnd
, REFGUID guid
)
1257 FIXME( "(%p)->(%p, %s): stub!\n", iface
, hwnd
, debugstr_guid(guid
) );
1261 static HRESULT WINAPI
JoyConfig8Impl_OpenTypeKey(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, DWORD security
, PHKEY key
)
1263 FIXME( "(%p)->(%s, 0x%08x, %p): stub!\n", iface
, debugstr_w(name
), security
, key
);
1267 static HRESULT WINAPI
JoyConfig8Impl_OpenAppStatusKey(IDirectInputJoyConfig8
*iface
, PHKEY key
)
1269 FIXME( "(%p)->(%p): stub!\n", iface
, key
);
1273 static const IDirectInput7AVtbl ddi7avt
= {
1274 IDirectInputAImpl_QueryInterface
,
1275 IDirectInputAImpl_AddRef
,
1276 IDirectInputAImpl_Release
,
1277 IDirectInputAImpl_CreateDevice
,
1278 IDirectInputAImpl_EnumDevices
,
1279 IDirectInputAImpl_GetDeviceStatus
,
1280 IDirectInputAImpl_RunControlPanel
,
1281 IDirectInputAImpl_Initialize
,
1282 IDirectInput2AImpl_FindDevice
,
1283 IDirectInput7AImpl_CreateDeviceEx
1286 static const IDirectInput7WVtbl ddi7wvt
= {
1287 IDirectInputWImpl_QueryInterface
,
1288 IDirectInputWImpl_AddRef
,
1289 IDirectInputWImpl_Release
,
1290 IDirectInputWImpl_CreateDevice
,
1291 IDirectInputWImpl_EnumDevices
,
1292 IDirectInputWImpl_GetDeviceStatus
,
1293 IDirectInputWImpl_RunControlPanel
,
1294 IDirectInputWImpl_Initialize
,
1295 IDirectInput2WImpl_FindDevice
,
1296 IDirectInput7WImpl_CreateDeviceEx
1299 static const IDirectInput8AVtbl ddi8avt
= {
1300 IDirectInput8AImpl_QueryInterface
,
1301 IDirectInput8AImpl_AddRef
,
1302 IDirectInput8AImpl_Release
,
1303 IDirectInput8AImpl_CreateDevice
,
1304 IDirectInput8AImpl_EnumDevices
,
1305 IDirectInput8AImpl_GetDeviceStatus
,
1306 IDirectInput8AImpl_RunControlPanel
,
1307 IDirectInput8AImpl_Initialize
,
1308 IDirectInput8AImpl_FindDevice
,
1309 IDirectInput8AImpl_EnumDevicesBySemantics
,
1310 IDirectInput8AImpl_ConfigureDevices
1313 static const IDirectInput8WVtbl ddi8wvt
= {
1314 IDirectInput8WImpl_QueryInterface
,
1315 IDirectInput8WImpl_AddRef
,
1316 IDirectInput8WImpl_Release
,
1317 IDirectInput8WImpl_CreateDevice
,
1318 IDirectInput8WImpl_EnumDevices
,
1319 IDirectInput8WImpl_GetDeviceStatus
,
1320 IDirectInput8WImpl_RunControlPanel
,
1321 IDirectInput8WImpl_Initialize
,
1322 IDirectInput8WImpl_FindDevice
,
1323 IDirectInput8WImpl_EnumDevicesBySemantics
,
1324 IDirectInput8WImpl_ConfigureDevices
1327 static const IDirectInputJoyConfig8Vtbl JoyConfig8vt
=
1329 JoyConfig8Impl_QueryInterface
,
1330 JoyConfig8Impl_AddRef
,
1331 JoyConfig8Impl_Release
,
1332 JoyConfig8Impl_Acquire
,
1333 JoyConfig8Impl_Unacquire
,
1334 JoyConfig8Impl_SetCooperativeLevel
,
1335 JoyConfig8Impl_SendNotify
,
1336 JoyConfig8Impl_EnumTypes
,
1337 JoyConfig8Impl_GetTypeInfo
,
1338 JoyConfig8Impl_SetTypeInfo
,
1339 JoyConfig8Impl_DeleteType
,
1340 JoyConfig8Impl_GetConfig
,
1341 JoyConfig8Impl_SetConfig
,
1342 JoyConfig8Impl_DeleteConfig
,
1343 JoyConfig8Impl_GetUserValues
,
1344 JoyConfig8Impl_SetUserValues
,
1345 JoyConfig8Impl_AddNewHardware
,
1346 JoyConfig8Impl_OpenTypeKey
,
1347 JoyConfig8Impl_OpenAppStatusKey
1350 /*******************************************************************************
1351 * DirectInput ClassFactory
1355 /* IUnknown fields */
1356 IClassFactory IClassFactory_iface
;
1358 } IClassFactoryImpl
;
1360 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
1362 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
1365 static HRESULT WINAPI
DICF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
1366 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1368 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
1369 return E_NOINTERFACE
;
1372 static ULONG WINAPI
DICF_AddRef(LPCLASSFACTORY iface
) {
1373 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1374 return InterlockedIncrement(&(This
->ref
));
1377 static ULONG WINAPI
DICF_Release(LPCLASSFACTORY iface
) {
1378 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1379 /* static class, won't be freed */
1380 return InterlockedDecrement(&(This
->ref
));
1383 static HRESULT WINAPI
DICF_CreateInstance(
1384 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
1386 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1388 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1389 if ( IsEqualGUID( &IID_IUnknown
, riid
) ||
1390 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
1391 IsEqualGUID( &IID_IDirectInputW
, riid
) ||
1392 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
1393 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
1394 IsEqualGUID( &IID_IDirectInput7A
, riid
) ||
1395 IsEqualGUID( &IID_IDirectInput7W
, riid
) ) {
1396 return create_directinput_instance(riid
, ppobj
, NULL
);
1399 FIXME("(%p,%p,%s,%p) Interface not found!\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1400 return E_NOINTERFACE
;
1403 static HRESULT WINAPI
DICF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
1404 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1405 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
1409 static const IClassFactoryVtbl DICF_Vtbl
= {
1410 DICF_QueryInterface
,
1413 DICF_CreateInstance
,
1416 static IClassFactoryImpl DINPUT_CF
= {{&DICF_Vtbl
}, 1 };
1418 /***********************************************************************
1419 * DllCanUnloadNow (DINPUT.@)
1421 HRESULT WINAPI
DllCanUnloadNow(void)
1426 /***********************************************************************
1427 * DllGetClassObject (DINPUT.@)
1429 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1431 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1432 if ( IsEqualCLSID( &IID_IClassFactory
, riid
) ) {
1434 IClassFactory_AddRef((IClassFactory
*)*ppv
);
1438 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1439 return CLASS_E_CLASSNOTAVAILABLE
;
1442 /***********************************************************************
1443 * DllRegisterServer (DINPUT.@)
1445 HRESULT WINAPI
DllRegisterServer(void)
1447 return __wine_register_resources( DINPUT_instance
);
1450 /***********************************************************************
1451 * DllUnregisterServer (DINPUT.@)
1453 HRESULT WINAPI
DllUnregisterServer(void)
1455 return __wine_unregister_resources( DINPUT_instance
);
1458 /******************************************************************************
1459 * DInput hook thread
1462 static LRESULT CALLBACK
LL_hook_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1464 IDirectInputImpl
*dinput
;
1467 if (code
!= HC_ACTION
) return CallNextHookEx( 0, code
, wparam
, lparam
);
1469 EnterCriticalSection( &dinput_hook_crit
);
1470 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1472 IDirectInputDeviceImpl
*dev
;
1474 EnterCriticalSection( &dinput
->crit
);
1475 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1476 if (dev
->acquired
&& dev
->event_proc
)
1478 TRACE("calling %p->%p (%lx %lx)\n", dev
, dev
->event_proc
, wparam
, lparam
);
1479 skip
|= dev
->event_proc( &dev
->IDirectInputDevice8A_iface
, wparam
, lparam
);
1481 LeaveCriticalSection( &dinput
->crit
);
1483 LeaveCriticalSection( &dinput_hook_crit
);
1485 return skip
? 1 : CallNextHookEx( 0, code
, wparam
, lparam
);
1488 static LRESULT CALLBACK
callwndproc_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1490 CWPSTRUCT
*msg
= (CWPSTRUCT
*)lparam
;
1491 IDirectInputImpl
*dinput
;
1494 if (code
!= HC_ACTION
|| (msg
->message
!= WM_KILLFOCUS
&&
1495 msg
->message
!= WM_ACTIVATEAPP
&& msg
->message
!= WM_ACTIVATE
))
1496 return CallNextHookEx( 0, code
, wparam
, lparam
);
1498 foreground
= GetForegroundWindow();
1500 EnterCriticalSection( &dinput_hook_crit
);
1502 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1504 IDirectInputDeviceImpl
*dev
;
1506 EnterCriticalSection( &dinput
->crit
);
1507 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1509 if (!dev
->acquired
) continue;
1511 if (msg
->hwnd
== dev
->win
&& msg
->hwnd
!= foreground
)
1513 TRACE( "%p window is not foreground - unacquiring %p\n", dev
->win
, dev
);
1514 IDirectInputDevice_Unacquire( &dev
->IDirectInputDevice8A_iface
);
1517 LeaveCriticalSection( &dinput
->crit
);
1519 LeaveCriticalSection( &dinput_hook_crit
);
1521 return CallNextHookEx( 0, code
, wparam
, lparam
);
1524 static DWORD WINAPI
hook_thread_proc(void *param
)
1526 static HHOOK kbd_hook
, mouse_hook
;
1529 /* Force creation of the message queue */
1530 PeekMessageW( &msg
, 0, 0, 0, PM_NOREMOVE
);
1531 SetEvent(*(LPHANDLE
)param
);
1533 while (GetMessageW( &msg
, 0, 0, 0 ))
1535 UINT kbd_cnt
= 0, mice_cnt
= 0;
1537 if (msg
.message
== WM_USER
+0x10)
1539 IDirectInputImpl
*dinput
;
1541 TRACE( "Processing hook change notification lp:%ld\n", msg
.lParam
);
1543 if (!msg
.wParam
&& !msg
.lParam
)
1545 if (kbd_hook
) UnhookWindowsHookEx( kbd_hook
);
1546 if (mouse_hook
) UnhookWindowsHookEx( mouse_hook
);
1547 kbd_hook
= mouse_hook
= NULL
;
1551 EnterCriticalSection( &dinput_hook_crit
);
1553 /* Count acquired keyboards and mice*/
1554 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1556 IDirectInputDeviceImpl
*dev
;
1558 EnterCriticalSection( &dinput
->crit
);
1559 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1561 if (!dev
->acquired
|| !dev
->event_proc
) continue;
1563 if (IsEqualGUID( &dev
->guid
, &GUID_SysKeyboard
) ||
1564 IsEqualGUID( &dev
->guid
, &DInput_Wine_Keyboard_GUID
))
1567 if (IsEqualGUID( &dev
->guid
, &GUID_SysMouse
) ||
1568 IsEqualGUID( &dev
->guid
, &DInput_Wine_Mouse_GUID
))
1571 LeaveCriticalSection( &dinput
->crit
);
1573 LeaveCriticalSection( &dinput_hook_crit
);
1575 if (kbd_cnt
&& !kbd_hook
)
1576 kbd_hook
= SetWindowsHookExW( WH_KEYBOARD_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1577 else if (!kbd_cnt
&& kbd_hook
)
1579 UnhookWindowsHookEx( kbd_hook
);
1583 if (mice_cnt
&& !mouse_hook
)
1584 mouse_hook
= SetWindowsHookExW( WH_MOUSE_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1585 else if (!mice_cnt
&& mouse_hook
)
1587 UnhookWindowsHookEx( mouse_hook
);
1591 TranslateMessage(&msg
);
1592 DispatchMessageW(&msg
);
1598 static DWORD hook_thread_id
;
1600 static CRITICAL_SECTION_DEBUG dinput_critsect_debug
=
1602 0, 0, &dinput_hook_crit
,
1603 { &dinput_critsect_debug
.ProcessLocksList
, &dinput_critsect_debug
.ProcessLocksList
},
1604 0, 0, { (DWORD_PTR
)(__FILE__
": dinput_hook_crit") }
1606 static CRITICAL_SECTION dinput_hook_crit
= { &dinput_critsect_debug
, -1, 0, 0, 0, 0 };
1608 static BOOL
check_hook_thread(void)
1610 static HANDLE hook_thread
;
1612 EnterCriticalSection(&dinput_hook_crit
);
1614 TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list
));
1615 if (!list_empty(&direct_input_list
) && !hook_thread
)
1619 event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1620 hook_thread
= CreateThread(NULL
, 0, hook_thread_proc
, &event
, 0, &hook_thread_id
);
1621 if (event
&& hook_thread
)
1625 handles
[1] = hook_thread
;
1626 WaitForMultipleObjects(2, handles
, FALSE
, INFINITE
);
1628 LeaveCriticalSection(&dinput_hook_crit
);
1631 else if (list_empty(&direct_input_list
) && hook_thread
)
1633 DWORD tid
= hook_thread_id
;
1636 PostThreadMessageW(tid
, WM_USER
+0x10, 0, 0);
1637 LeaveCriticalSection(&dinput_hook_crit
);
1639 /* wait for hook thread to exit */
1640 WaitForSingleObject(hook_thread
, INFINITE
);
1641 CloseHandle(hook_thread
);
1645 LeaveCriticalSection(&dinput_hook_crit
);
1647 return hook_thread_id
!= 0;
1650 void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface
)
1652 static HHOOK callwndproc_hook
;
1653 static ULONG foreground_cnt
;
1654 IDirectInputDeviceImpl
*dev
= impl_from_IDirectInputDevice8W(iface
);
1656 EnterCriticalSection(&dinput_hook_crit
);
1658 if (dev
->dwCoopLevel
& DISCL_FOREGROUND
)
1666 if (foreground_cnt
&& !callwndproc_hook
)
1667 callwndproc_hook
= SetWindowsHookExW( WH_CALLWNDPROC
, callwndproc_proc
,
1668 DINPUT_instance
, GetCurrentThreadId() );
1669 else if (!foreground_cnt
&& callwndproc_hook
)
1671 UnhookWindowsHookEx( callwndproc_hook
);
1672 callwndproc_hook
= NULL
;
1675 PostThreadMessageW( hook_thread_id
, WM_USER
+0x10, 1, 0 );
1677 LeaveCriticalSection(&dinput_hook_crit
);
1680 void check_dinput_events(void)
1682 /* Windows does not do that, but our current implementation of winex11
1683 * requires periodic event polling to forward events to the wineserver.
1685 * We have to call this function from multiple places, because:
1686 * - some games do not explicitly poll for mouse events
1687 * (for example Culpa Innata)
1688 * - some games only poll the device, and neither keyboard nor mouse
1689 * (for example Civilization: Call to Power 2)
1691 MsgWaitForMultipleObjectsEx(0, NULL
, 0, QS_ALLINPUT
, 0);
1694 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
1698 case DLL_PROCESS_ATTACH
:
1699 DisableThreadLibraryCalls(inst
);
1700 DINPUT_instance
= inst
;
1702 case DLL_PROCESS_DETACH
:
1703 if (reserved
) break;
1704 DeleteCriticalSection(&dinput_hook_crit
);