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
)
187 case 0: return "All devices";
188 case DIDEVTYPE_MOUSE
: return "DIDEVTYPE_MOUSE";
189 case DIDEVTYPE_KEYBOARD
: return "DIDEVTYPE_KEYBOARD";
190 case DIDEVTYPE_JOYSTICK
: return "DIDEVTYPE_JOYSTICK";
191 case DIDEVTYPE_DEVICE
: return "DIDEVTYPE_DEVICE";
192 default: return "Unknown";
196 static void _dump_EnumDevices_dwFlags(DWORD dwFlags
)
198 if (TRACE_ON(dinput
)) {
200 static const struct {
204 #define FE(x) { x, #x}
205 FE(DIEDFL_ALLDEVICES
),
206 FE(DIEDFL_ATTACHEDONLY
),
207 FE(DIEDFL_FORCEFEEDBACK
),
208 FE(DIEDFL_INCLUDEALIASES
),
209 FE(DIEDFL_INCLUDEPHANTOMS
),
210 FE(DIEDFL_INCLUDEHIDDEN
)
215 TRACE("DIEDFL_ALLDEVICES\n");
218 for (i
= 0; i
< (sizeof(flags
) / sizeof(flags
[0])); i
++)
219 if (flags
[i
].mask
& dwFlags
)
220 TRACE("%s ",flags
[i
].name
);
225 static void _dump_diactionformatA(LPDIACTIONFORMATA lpdiActionFormat
)
229 TRACE("diaf.dwSize = %d\n", lpdiActionFormat
->dwSize
);
230 TRACE("diaf.dwActionSize = %d\n", lpdiActionFormat
->dwActionSize
);
231 TRACE("diaf.dwDataSize = %d\n", lpdiActionFormat
->dwDataSize
);
232 TRACE("diaf.dwNumActions = %d\n", lpdiActionFormat
->dwNumActions
);
233 TRACE("diaf.rgoAction = %p\n", lpdiActionFormat
->rgoAction
);
234 TRACE("diaf.guidActionMap = %s\n", debugstr_guid(&lpdiActionFormat
->guidActionMap
));
235 TRACE("diaf.dwGenre = 0x%08x\n", lpdiActionFormat
->dwGenre
);
236 TRACE("diaf.dwBufferSize = %d\n", lpdiActionFormat
->dwBufferSize
);
237 TRACE("diaf.lAxisMin = %d\n", lpdiActionFormat
->lAxisMin
);
238 TRACE("diaf.lAxisMax = %d\n", lpdiActionFormat
->lAxisMax
);
239 TRACE("diaf.hInstString = %p\n", lpdiActionFormat
->hInstString
);
240 TRACE("diaf.ftTimeStamp ...\n");
241 TRACE("diaf.dwCRC = 0x%x\n", lpdiActionFormat
->dwCRC
);
242 TRACE("diaf.tszActionMap = %s\n", debugstr_a(lpdiActionFormat
->tszActionMap
));
243 for (i
= 0; i
< lpdiActionFormat
->dwNumActions
; i
++)
245 TRACE("diaf.rgoAction[%u]:\n", i
);
246 TRACE("\tuAppData=0x%lx\n", lpdiActionFormat
->rgoAction
[i
].uAppData
);
247 TRACE("\tdwSemantic=0x%08x\n", lpdiActionFormat
->rgoAction
[i
].dwSemantic
);
248 TRACE("\tdwFlags=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwFlags
);
249 TRACE("\tszActionName=%s\n", debugstr_a(lpdiActionFormat
->rgoAction
[i
].u
.lptszActionName
));
250 TRACE("\tguidInstance=%s\n", debugstr_guid(&lpdiActionFormat
->rgoAction
[i
].guidInstance
));
251 TRACE("\tdwObjID=0x%x\n", lpdiActionFormat
->rgoAction
[i
].dwObjID
);
252 TRACE("\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
->dwNumActions
; 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
->dwNumActions
; i
++)
336 if ((lpdiaf
->rgoAction
[i
].dwSemantic
& genre
) == genre
)
337 priorityFlags
|= DIEDBS_MAPPEDPRI1
;
339 return priorityFlags
;
342 #if defined __i386__ && defined _MSC_VER
343 __declspec(naked
) BOOL
enum_callback_wrapper(void *callback
, const void *instance
, void *ref
)
356 #elif defined __i386__ && defined __GNUC__
357 extern BOOL
enum_callback_wrapper(void *callback
, const void *instance
, void *ref
);
358 __ASM_GLOBAL_FUNC( enum_callback_wrapper
,
360 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
361 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
363 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
368 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
369 __ASM_CFI(".cfi_same_value %ebp\n\t")
372 #define enum_callback_wrapper(callback, instance, ref) (callback)((instance), (ref))
375 /******************************************************************************
376 * IDirectInputA_EnumDevices
378 static HRESULT WINAPI
IDirectInputAImpl_EnumDevices(
379 LPDIRECTINPUT7A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
380 LPVOID pvRef
, DWORD dwFlags
)
382 IDirectInputImpl
*This
= impl_from_IDirectInput7A(iface
);
383 DIDEVICEINSTANCEA devInstance
;
387 TRACE("(this=%p,0x%04x '%s',%p,%p,%04x)\n",
388 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
),
389 lpCallback
, pvRef
, dwFlags
);
390 _dump_EnumDevices_dwFlags(dwFlags
);
393 dwFlags
& ~(DIEDFL_ATTACHEDONLY
| DIEDFL_FORCEFEEDBACK
| DIEDFL_INCLUDEALIASES
| DIEDFL_INCLUDEPHANTOMS
| DIEDFL_INCLUDEHIDDEN
) ||
394 (dwDevType
> DI8DEVCLASS_GAMECTRL
&& dwDevType
< DI8DEVTYPE_DEVICE
) || dwDevType
> DI8DEVTYPE_SUPPLEMENTAL
)
395 return DIERR_INVALIDPARAM
;
397 if (!This
->initialized
)
398 return DIERR_NOTINITIALIZED
;
400 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
401 if (!dinput_devices
[i
]->enum_deviceA
) continue;
402 for (j
= 0, r
= S_OK
; SUCCEEDED(r
); j
++) {
403 devInstance
.dwSize
= sizeof(devInstance
);
404 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
405 r
= dinput_devices
[i
]->enum_deviceA(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
);
407 if (enum_callback_wrapper(lpCallback
, &devInstance
, pvRef
) == DIENUM_STOP
)
414 /******************************************************************************
415 * IDirectInputW_EnumDevices
417 static HRESULT WINAPI
IDirectInputWImpl_EnumDevices(
418 LPDIRECTINPUT7W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
419 LPVOID pvRef
, DWORD dwFlags
)
421 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
422 DIDEVICEINSTANCEW devInstance
;
427 TRACE("(this=%p,0x%04x '%s',%p,%p,%04x)\n",
428 This
, dwDevType
, _dump_DIDEVTYPE_value(dwDevType
),
429 lpCallback
, pvRef
, dwFlags
);
430 _dump_EnumDevices_dwFlags(dwFlags
);
433 dwFlags
& ~(DIEDFL_ATTACHEDONLY
| DIEDFL_FORCEFEEDBACK
| DIEDFL_INCLUDEALIASES
| DIEDFL_INCLUDEPHANTOMS
| DIEDFL_INCLUDEHIDDEN
) ||
434 (dwDevType
> DI8DEVCLASS_GAMECTRL
&& dwDevType
< DI8DEVTYPE_DEVICE
) || dwDevType
> DI8DEVTYPE_SUPPLEMENTAL
)
435 return DIERR_INVALIDPARAM
;
437 if (!This
->initialized
)
438 return DIERR_NOTINITIALIZED
;
440 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++) {
441 if (!dinput_devices
[i
]->enum_deviceW
) continue;
442 for (j
= 0, r
= S_OK
; SUCCEEDED(r
); j
++) {
443 devInstance
.dwSize
= sizeof(devInstance
);
444 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
445 r
= dinput_devices
[i
]->enum_deviceW(dwDevType
, dwFlags
, &devInstance
, This
->dwVersion
, j
);
447 if (enum_callback_wrapper(lpCallback
, &devInstance
, pvRef
) == DIENUM_STOP
)
455 static ULONG WINAPI
IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface
)
457 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
458 ULONG ref
= InterlockedIncrement(&This
->ref
);
460 TRACE( "(%p) incrementing from %d\n", This
, ref
- 1);
464 static ULONG WINAPI
IDirectInputWImpl_AddRef(LPDIRECTINPUT7W iface
)
466 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
467 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
470 static ULONG WINAPI
IDirectInputAImpl_Release(LPDIRECTINPUT7A iface
)
472 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
473 ULONG ref
= InterlockedDecrement( &This
->ref
);
475 TRACE( "(%p) releasing from %d\n", This
, ref
+ 1 );
479 uninitialize_directinput_instance( This
);
480 HeapFree( GetProcessHeap(), 0, This
);
486 static ULONG WINAPI
IDirectInputWImpl_Release(LPDIRECTINPUT7W iface
)
488 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
489 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
492 static HRESULT WINAPI
IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface
, REFIID riid
, LPVOID
*ppobj
)
494 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
496 TRACE( "(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
501 if (IsEqualGUID( &IID_IUnknown
, riid
) ||
502 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
503 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
504 IsEqualGUID( &IID_IDirectInput7A
, riid
))
506 *ppobj
= &This
->IDirectInput7A_iface
;
507 IUnknown_AddRef( (IUnknown
*)*ppobj
);
512 if (IsEqualGUID( &IID_IDirectInputW
, riid
) ||
513 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
514 IsEqualGUID( &IID_IDirectInput7W
, riid
))
516 *ppobj
= &This
->IDirectInput7W_iface
;
517 IUnknown_AddRef( (IUnknown
*)*ppobj
);
522 if (IsEqualGUID( &IID_IDirectInput8A
, riid
))
524 *ppobj
= &This
->IDirectInput8A_iface
;
525 IUnknown_AddRef( (IUnknown
*)*ppobj
);
530 if (IsEqualGUID( &IID_IDirectInput8W
, riid
))
532 *ppobj
= &This
->IDirectInput8W_iface
;
533 IUnknown_AddRef( (IUnknown
*)*ppobj
);
538 if (IsEqualGUID( &IID_IDirectInputJoyConfig8
, riid
))
540 *ppobj
= &This
->IDirectInputJoyConfig8_iface
;
541 IUnknown_AddRef( (IUnknown
*)*ppobj
);
546 FIXME( "Unsupported interface: %s\n", debugstr_guid(riid
));
548 return E_NOINTERFACE
;
551 static HRESULT WINAPI
IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface
, REFIID riid
, LPVOID
*ppobj
)
553 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
554 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
557 static HRESULT
initialize_directinput_instance(IDirectInputImpl
*This
, DWORD dwVersion
)
559 if (!This
->initialized
)
561 This
->dwVersion
= dwVersion
;
562 This
->evsequence
= 1;
564 InitializeCriticalSection( &This
->crit
);
565 This
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IDirectInputImpl*->crit");
567 list_init( &This
->devices_list
);
569 /* Add self to the list of the IDirectInputs */
570 EnterCriticalSection( &dinput_hook_crit
);
571 list_add_head( &direct_input_list
, &This
->entry
);
572 LeaveCriticalSection( &dinput_hook_crit
);
574 This
->initialized
= TRUE
;
576 if (!check_hook_thread())
578 uninitialize_directinput_instance( This
);
579 return DIERR_GENERIC
;
586 static void uninitialize_directinput_instance(IDirectInputImpl
*This
)
588 if (This
->initialized
)
590 /* Remove self from the list of the IDirectInputs */
591 EnterCriticalSection( &dinput_hook_crit
);
592 list_remove( &This
->entry
);
593 LeaveCriticalSection( &dinput_hook_crit
);
597 This
->crit
.DebugInfo
->Spare
[0] = 0;
598 DeleteCriticalSection( &This
->crit
);
600 This
->initialized
= FALSE
;
604 enum directinput_versions
606 DIRECTINPUT_VERSION_300
= 0x0300,
607 DIRECTINPUT_VERSION_500
= 0x0500,
608 DIRECTINPUT_VERSION_50A
= 0x050A,
609 DIRECTINPUT_VERSION_5B2
= 0x05B2,
610 DIRECTINPUT_VERSION_602
= 0x0602,
611 DIRECTINPUT_VERSION_61A
= 0x061A,
612 DIRECTINPUT_VERSION_700
= 0x0700,
615 static HRESULT WINAPI
IDirectInputAImpl_Initialize(LPDIRECTINPUT7A iface
, HINSTANCE hinst
, DWORD version
)
617 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
619 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
622 return DIERR_INVALIDPARAM
;
623 else if (version
== 0)
624 return DIERR_NOTINITIALIZED
;
625 else if (version
> DIRECTINPUT_VERSION_700
)
626 return DIERR_OLDDIRECTINPUTVERSION
;
627 else if (version
!= DIRECTINPUT_VERSION_300
&& version
!= DIRECTINPUT_VERSION_500
&&
628 version
!= DIRECTINPUT_VERSION_50A
&& version
!= DIRECTINPUT_VERSION_5B2
&&
629 version
!= DIRECTINPUT_VERSION_602
&& version
!= DIRECTINPUT_VERSION_61A
&&
630 version
!= DIRECTINPUT_VERSION_700
&& version
!= DIRECTINPUT_VERSION
)
631 return DIERR_BETADIRECTINPUTVERSION
;
633 return initialize_directinput_instance(This
, version
);
636 static HRESULT WINAPI
IDirectInputWImpl_Initialize(LPDIRECTINPUT7W iface
, HINSTANCE hinst
, DWORD x
)
638 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
639 return IDirectInputAImpl_Initialize( &This
->IDirectInput7A_iface
, hinst
, x
);
642 static HRESULT WINAPI
IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUT7A iface
, REFGUID rguid
)
644 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
646 LPDIRECTINPUTDEVICEA device
;
648 TRACE( "(%p)->(%s)\n", This
, debugstr_guid(rguid
) );
650 if (!rguid
) return E_POINTER
;
651 if (!This
->initialized
)
652 return DIERR_NOTINITIALIZED
;
654 hr
= IDirectInput_CreateDevice( iface
, rguid
, &device
, NULL
);
655 if (hr
!= DI_OK
) return DI_NOTATTACHED
;
657 IUnknown_Release( device
);
662 static HRESULT WINAPI
IDirectInputWImpl_GetDeviceStatus(LPDIRECTINPUT7W iface
, REFGUID rguid
)
664 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
665 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
668 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUT7A iface
,
672 WCHAR control_exeW
[] = {'c','o','n','t','r','o','l','.','e','x','e',0};
673 STARTUPINFOW si
= {0};
674 PROCESS_INFORMATION pi
;
676 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
678 TRACE( "(%p)->(%p, %08x)\n", This
, hwndOwner
, dwFlags
);
680 if (hwndOwner
&& !IsWindow(hwndOwner
))
684 return DIERR_INVALIDPARAM
;
686 if (!This
->initialized
)
687 return DIERR_NOTINITIALIZED
;
689 if (!CreateProcessW(NULL
, control_exeW
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
))
690 return HRESULT_FROM_WIN32(GetLastError());
695 static HRESULT WINAPI
IDirectInputWImpl_RunControlPanel(LPDIRECTINPUT7W iface
, HWND hwndOwner
, DWORD dwFlags
)
697 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
698 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
701 static HRESULT WINAPI
IDirectInput2AImpl_FindDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
702 LPCSTR pszName
, LPGUID pguidInstance
)
704 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
706 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), pszName
, pguidInstance
);
711 static HRESULT WINAPI
IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
712 LPCWSTR pszName
, LPGUID pguidInstance
)
714 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
716 FIXME( "(%p)->(%s, %s, %p): stub\n", This
, debugstr_guid(rguid
), debugstr_w(pszName
), pguidInstance
);
721 static HRESULT
create_device(IDirectInputImpl
*This
, REFGUID rguid
, REFIID riid
, LPVOID
*pvOut
, BOOL unicode
)
728 if (!rguid
|| !pvOut
)
731 if (!This
->initialized
)
732 return DIERR_NOTINITIALIZED
;
734 /* Loop on all the devices to see if anyone matches the given GUID */
735 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
739 if (!dinput_devices
[i
]->create_device
) continue;
740 if ((ret
= dinput_devices
[i
]->create_device(This
, rguid
, riid
, pvOut
, unicode
)) == DI_OK
)
744 WARN("invalid device GUID %s\n", debugstr_guid(rguid
));
745 return DIERR_DEVICENOTREG
;
748 static HRESULT WINAPI
IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface
, REFGUID rguid
,
749 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
751 IDirectInputImpl
*This
= impl_from_IDirectInput7A( iface
);
753 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
755 return create_device(This
, rguid
, riid
, pvOut
, FALSE
);
758 static HRESULT WINAPI
IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface
, REFGUID rguid
,
759 REFIID riid
, LPVOID
* pvOut
, LPUNKNOWN lpUnknownOuter
)
761 IDirectInputImpl
*This
= impl_from_IDirectInput7W( iface
);
763 TRACE("(%p)->(%s, %s, %p, %p)\n", This
, debugstr_guid(rguid
), debugstr_guid(riid
), pvOut
, lpUnknownOuter
);
765 return create_device(This
, rguid
, riid
, pvOut
, TRUE
);
768 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface
, REFGUID rguid
,
769 LPDIRECTINPUTDEVICEA
* pdev
, LPUNKNOWN punk
)
771 return IDirectInput7AImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
774 static HRESULT WINAPI
IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface
, REFGUID rguid
,
775 LPDIRECTINPUTDEVICEW
* pdev
, LPUNKNOWN punk
)
777 return IDirectInput7WImpl_CreateDeviceEx(iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
780 /*******************************************************************************
784 static ULONG WINAPI
IDirectInput8AImpl_AddRef(LPDIRECTINPUT8A iface
)
786 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
787 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
790 static ULONG WINAPI
IDirectInput8WImpl_AddRef(LPDIRECTINPUT8W iface
)
792 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
793 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
796 static HRESULT WINAPI
IDirectInput8AImpl_QueryInterface(LPDIRECTINPUT8A iface
, REFIID riid
, LPVOID
*ppobj
)
798 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
799 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
802 static HRESULT WINAPI
IDirectInput8WImpl_QueryInterface(LPDIRECTINPUT8W iface
, REFIID riid
, LPVOID
*ppobj
)
804 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
805 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
808 static ULONG WINAPI
IDirectInput8AImpl_Release(LPDIRECTINPUT8A iface
)
810 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
811 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
814 static ULONG WINAPI
IDirectInput8WImpl_Release(LPDIRECTINPUT8W iface
)
816 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
817 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
820 static HRESULT WINAPI
IDirectInput8AImpl_CreateDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
,
821 LPDIRECTINPUTDEVICE8A
* pdev
, LPUNKNOWN punk
)
823 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
824 return IDirectInput7AImpl_CreateDeviceEx( &This
->IDirectInput7A_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
827 static HRESULT WINAPI
IDirectInput8WImpl_CreateDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
,
828 LPDIRECTINPUTDEVICE8W
* pdev
, LPUNKNOWN punk
)
830 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
831 return IDirectInput7WImpl_CreateDeviceEx( &This
->IDirectInput7W_iface
, rguid
, NULL
, (LPVOID
*)pdev
, punk
);
834 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevices(LPDIRECTINPUT8A iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
835 LPVOID pvRef
, DWORD dwFlags
)
837 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
838 return IDirectInputAImpl_EnumDevices( &This
->IDirectInput7A_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
841 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKW lpCallback
,
842 LPVOID pvRef
, DWORD dwFlags
)
844 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
845 return IDirectInputWImpl_EnumDevices( &This
->IDirectInput7W_iface
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
848 static HRESULT WINAPI
IDirectInput8AImpl_GetDeviceStatus(LPDIRECTINPUT8A iface
, REFGUID rguid
)
850 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
851 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
854 static HRESULT WINAPI
IDirectInput8WImpl_GetDeviceStatus(LPDIRECTINPUT8W iface
, REFGUID rguid
)
856 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
857 return IDirectInputAImpl_GetDeviceStatus( &This
->IDirectInput7A_iface
, rguid
);
860 static HRESULT WINAPI
IDirectInput8AImpl_RunControlPanel(LPDIRECTINPUT8A iface
, HWND hwndOwner
, DWORD dwFlags
)
862 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
863 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
866 static HRESULT WINAPI
IDirectInput8WImpl_RunControlPanel(LPDIRECTINPUT8W iface
, HWND hwndOwner
, DWORD dwFlags
)
868 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
869 return IDirectInputAImpl_RunControlPanel( &This
->IDirectInput7A_iface
, hwndOwner
, dwFlags
);
872 static HRESULT WINAPI
IDirectInput8AImpl_Initialize(LPDIRECTINPUT8A iface
, HINSTANCE hinst
, DWORD version
)
874 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
876 TRACE("(%p)->(%p, 0x%04x)\n", iface
, hinst
, version
);
879 return DIERR_INVALIDPARAM
;
880 else if (version
== 0)
881 return DIERR_NOTINITIALIZED
;
882 else if (version
< DIRECTINPUT_VERSION
)
883 return DIERR_BETADIRECTINPUTVERSION
;
884 else if (version
> DIRECTINPUT_VERSION
)
885 return DIERR_OLDDIRECTINPUTVERSION
;
887 return initialize_directinput_instance(This
, version
);
890 static HRESULT WINAPI
IDirectInput8WImpl_Initialize(LPDIRECTINPUT8W iface
, HINSTANCE hinst
, DWORD version
)
892 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
893 return IDirectInput8AImpl_Initialize( &This
->IDirectInput8A_iface
, hinst
, version
);
896 static HRESULT WINAPI
IDirectInput8AImpl_FindDevice(LPDIRECTINPUT8A iface
, REFGUID rguid
, LPCSTR pszName
, LPGUID pguidInstance
)
898 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
899 return IDirectInput2AImpl_FindDevice( &This
->IDirectInput7A_iface
, rguid
, pszName
, pguidInstance
);
902 static HRESULT WINAPI
IDirectInput8WImpl_FindDevice(LPDIRECTINPUT8W iface
, REFGUID rguid
, LPCWSTR pszName
, LPGUID pguidInstance
)
904 IDirectInputImpl
*This
= impl_from_IDirectInput8W( iface
);
905 return IDirectInput2WImpl_FindDevice( &This
->IDirectInput7W_iface
, rguid
, pszName
, pguidInstance
);
908 static HRESULT WINAPI
IDirectInput8AImpl_EnumDevicesBySemantics(
909 LPDIRECTINPUT8A iface
, LPCSTR ptszUserName
, LPDIACTIONFORMATA lpdiActionFormat
,
910 LPDIENUMDEVICESBYSEMANTICSCBA lpCallback
,
911 LPVOID pvRef
, DWORD dwFlags
914 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
915 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
916 IDirectInputImpl
*This
= impl_from_IDirectInput8A( iface
);
917 DIDEVICEINSTANCEA didevi
;
918 LPDIRECTINPUTDEVICE8A lpdid
;
923 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_a(ptszUserName
), lpdiActionFormat
,
924 lpCallback
, pvRef
, dwFlags
);
925 #define X(x) if (dwFlags & x) FIXME("\tdwFlags |= "#x"\n");
926 X(DIEDBSFL_ATTACHEDONLY
)
928 X(DIEDBSFL_FORCEFEEDBACK
)
929 X(DIEDBSFL_AVAILABLEDEVICES
)
930 X(DIEDBSFL_MULTIMICEKEYBOARDS
)
931 X(DIEDBSFL_NONGAMINGDEVICES
)
934 _dump_diactionformatA(lpdiActionFormat
);
936 didevi
.dwSize
= sizeof(didevi
);
938 /* Enumerate all the joysticks */
939 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
943 if (!dinput_devices
[i
]->enum_deviceA
) continue;
945 for (j
= 0, enumSuccess
= S_OK
; SUCCEEDED(enumSuccess
); j
++)
947 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
949 callbackFlags
= diactionformat_priorityA(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
950 /* Default behavior is to enumerate attached game controllers */
951 enumSuccess
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
952 if (enumSuccess
== S_OK
)
954 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
956 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
962 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
964 /* Enumerate keyboard and mouse */
965 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
967 callbackFlags
= diactionformat_priorityA(lpdiActionFormat
, actionMasks
[i
]);
969 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
970 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
972 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
979 static HRESULT WINAPI
IDirectInput8WImpl_EnumDevicesBySemantics(
980 LPDIRECTINPUT8W iface
, LPCWSTR ptszUserName
, LPDIACTIONFORMATW lpdiActionFormat
,
981 LPDIENUMDEVICESBYSEMANTICSCBW lpCallback
,
982 LPVOID pvRef
, DWORD dwFlags
985 static REFGUID guids
[2] = { &GUID_SysKeyboard
, &GUID_SysMouse
};
986 static const DWORD actionMasks
[] = { DIKEYBOARD_MASK
, DIMOUSE_MASK
};
987 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
988 DIDEVICEINSTANCEW didevi
;
989 LPDIRECTINPUTDEVICE8W lpdid
;
993 FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This
, debugstr_w(ptszUserName
), lpdiActionFormat
,
994 lpCallback
, pvRef
, dwFlags
);
996 didevi
.dwSize
= sizeof(didevi
);
998 /* Enumerate all the joysticks */
999 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
1001 HRESULT enumSuccess
;
1003 if (!dinput_devices
[i
]->enum_deviceW
) continue;
1005 for (j
= 0, enumSuccess
= S_OK
; SUCCEEDED(enumSuccess
); j
++)
1007 TRACE(" - checking device %u ('%s')\n", i
, dinput_devices
[i
]->name
);
1009 callbackFlags
= diactionformat_priorityW(lpdiActionFormat
, lpdiActionFormat
->dwGenre
);
1010 /* Default behavior is to enumerate attached game controllers */
1011 enumSuccess
= dinput_devices
[i
]->enum_deviceW(DI8DEVCLASS_GAMECTRL
, DIEDFL_ATTACHEDONLY
| dwFlags
, &didevi
, This
->dwVersion
, j
);
1012 if (enumSuccess
== S_OK
)
1014 IDirectInput_CreateDevice(iface
, &didevi
.guidInstance
, &lpdid
, NULL
);
1016 if (lpCallback(&didevi
, lpdid
, callbackFlags
, 0, pvRef
) == DIENUM_STOP
)
1022 if (dwFlags
& DIEDBSFL_FORCEFEEDBACK
) return DI_OK
;
1024 /* Enumerate keyboard and mouse */
1025 for(i
=0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++)
1027 callbackFlags
= diactionformat_priorityW(lpdiActionFormat
, actionMasks
[i
]);
1029 IDirectInput_CreateDevice(iface
, guids
[i
], &lpdid
, NULL
);
1030 IDirectInputDevice_GetDeviceInfo(lpdid
, &didevi
);
1032 if (lpCallback(&didevi
, lpdid
, callbackFlags
, sizeof(guids
)/sizeof(guids
[0]) - (i
+1), pvRef
) == DIENUM_STOP
)
1039 static HRESULT WINAPI
IDirectInput8WImpl_ConfigureDevices(
1040 LPDIRECTINPUT8W iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1041 LPDICONFIGUREDEVICESPARAMSW lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1044 IDirectInputImpl
*This
= impl_from_IDirectInput8W(iface
);
1046 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1048 /* Call helper function in config.c to do the real work */
1049 return _configure_devices(iface
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1052 static HRESULT WINAPI
IDirectInput8AImpl_ConfigureDevices(
1053 LPDIRECTINPUT8A iface
, LPDICONFIGUREDEVICESCALLBACK lpdiCallback
,
1054 LPDICONFIGUREDEVICESPARAMSA lpdiCDParams
, DWORD dwFlags
, LPVOID pvRefData
1057 IDirectInputImpl
*This
= impl_from_IDirectInput8A(iface
);
1058 DIACTIONFORMATW diafW
;
1059 DICONFIGUREDEVICESPARAMSW diCDParamsW
;
1063 FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This
, lpdiCallback
, lpdiCDParams
, dwFlags
, pvRefData
);
1065 /* Copy parameters */
1066 diCDParamsW
.dwSize
= sizeof(DICONFIGUREDEVICESPARAMSW
);
1067 diCDParamsW
.dwcFormats
= lpdiCDParams
->dwcFormats
;
1068 diCDParamsW
.lprgFormats
= &diafW
;
1069 diCDParamsW
.hwnd
= lpdiCDParams
->hwnd
;
1071 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiCDParams
->lprgFormats
->dwNumActions
);
1072 _copy_diactionformatAtoW(&diafW
, lpdiCDParams
->lprgFormats
);
1074 /* Copy action names */
1075 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1077 const char* from
= lpdiCDParams
->lprgFormats
->rgoAction
[i
].u
.lptszActionName
;
1078 int len
= MultiByteToWideChar(CP_ACP
, 0, from
, -1, NULL
, 0);
1079 WCHAR
*to
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*len
);
1081 MultiByteToWideChar(CP_ACP
, 0, from
, -1, to
, len
);
1082 diafW
.rgoAction
[i
].u
.lptszActionName
= to
;
1085 hr
= IDirectInput8WImpl_ConfigureDevices(&This
->IDirectInput8W_iface
, lpdiCallback
, &diCDParamsW
, dwFlags
, pvRefData
);
1087 /* Copy back configuration */
1089 _copy_diactionformatWtoA(lpdiCDParams
->lprgFormats
, &diafW
);
1092 for (i
=0; i
< diafW
.dwNumActions
; i
++)
1093 HeapFree(GetProcessHeap(), 0, (void*) diafW
.rgoAction
[i
].u
.lptszActionName
);
1095 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
1100 /*****************************************************************************
1101 * IDirectInputJoyConfig8 interface
1104 static inline IDirectInputImpl
*impl_from_IDirectInputJoyConfig8(IDirectInputJoyConfig8
*iface
)
1106 return CONTAINING_RECORD( iface
, IDirectInputImpl
, IDirectInputJoyConfig8_iface
);
1109 static HRESULT WINAPI
JoyConfig8Impl_QueryInterface(IDirectInputJoyConfig8
*iface
, REFIID riid
, void** ppobj
)
1111 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1112 return IDirectInputAImpl_QueryInterface( &This
->IDirectInput7A_iface
, riid
, ppobj
);
1115 static ULONG WINAPI
JoyConfig8Impl_AddRef(IDirectInputJoyConfig8
*iface
)
1117 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1118 return IDirectInputAImpl_AddRef( &This
->IDirectInput7A_iface
);
1121 static ULONG WINAPI
JoyConfig8Impl_Release(IDirectInputJoyConfig8
*iface
)
1123 IDirectInputImpl
*This
= impl_from_IDirectInputJoyConfig8( iface
);
1124 return IDirectInputAImpl_Release( &This
->IDirectInput7A_iface
);
1127 static HRESULT WINAPI
JoyConfig8Impl_Acquire(IDirectInputJoyConfig8
*iface
)
1129 FIXME( "(%p): stub!\n", iface
);
1133 static HRESULT WINAPI
JoyConfig8Impl_Unacquire(IDirectInputJoyConfig8
*iface
)
1135 FIXME( "(%p): stub!\n", iface
);
1139 static HRESULT WINAPI
JoyConfig8Impl_SetCooperativeLevel(IDirectInputJoyConfig8
*iface
, HWND hwnd
, DWORD flags
)
1141 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, hwnd
, flags
);
1145 static HRESULT WINAPI
JoyConfig8Impl_SendNotify(IDirectInputJoyConfig8
*iface
)
1147 FIXME( "(%p): stub!\n", iface
);
1151 static HRESULT WINAPI
JoyConfig8Impl_EnumTypes(IDirectInputJoyConfig8
*iface
, LPDIJOYTYPECALLBACK cb
, void *ref
)
1153 FIXME( "(%p)->(%p, %p): stub!\n", iface
, cb
, ref
);
1157 static HRESULT WINAPI
JoyConfig8Impl_GetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPDIJOYTYPEINFO info
, DWORD flags
)
1159 FIXME( "(%p)->(%s, %p, 0x%08x): stub!\n", iface
, debugstr_w(name
), info
, flags
);
1163 static HRESULT WINAPI
JoyConfig8Impl_SetTypeInfo(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, LPCDIJOYTYPEINFO info
, DWORD flags
,
1166 FIXME( "(%p)->(%s, %p, 0x%08x, %s): stub!\n", iface
, debugstr_w(name
), info
, flags
, debugstr_w(new_name
) );
1170 static HRESULT WINAPI
JoyConfig8Impl_DeleteType(IDirectInputJoyConfig8
*iface
, LPCWSTR name
)
1172 FIXME( "(%p)->(%s): stub!\n", iface
, debugstr_w(name
) );
1176 static HRESULT WINAPI
JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPDIJOYCONFIG info
, DWORD flags
)
1178 IDirectInputImpl
*di
= impl_from_IDirectInputJoyConfig8(iface
);
1183 FIXME("(%p)->(%d, %p, 0x%08x): semi-stub!\n", iface
, id
, info
, flags
);
1185 #define X(x) if (flags & x) FIXME("\tflags |= "#x"\n");
1186 X(DIJC_GUIDINSTANCE
)
1187 X(DIJC_REGHWCONFIGTYPE
)
1192 /* Enumerate all joysticks in order */
1193 for (i
= 0; i
< NB_DINPUT_DEVICES
; i
++)
1195 if (!dinput_devices
[i
]->enum_deviceA
) continue;
1197 for (j
= 0, r
= S_OK
; SUCCEEDED(r
); j
++)
1199 DIDEVICEINSTANCEA dev
;
1200 dev
.dwSize
= sizeof(dev
);
1201 if ((r
= dinput_devices
[i
]->enum_deviceA(DI8DEVCLASS_GAMECTRL
, 0, &dev
, di
->dwVersion
, j
)) == S_OK
)
1203 /* Only take into account the chosen id */
1206 if (flags
& DIJC_GUIDINSTANCE
)
1207 info
->guidInstance
= dev
.guidInstance
;
1216 return DIERR_NOMOREITEMS
;
1219 static HRESULT WINAPI
JoyConfig8Impl_SetConfig(IDirectInputJoyConfig8
*iface
, UINT id
, LPCDIJOYCONFIG info
, DWORD flags
)
1221 FIXME( "(%p)->(%d, %p, 0x%08x): stub!\n", iface
, id
, info
, flags
);
1225 static HRESULT WINAPI
JoyConfig8Impl_DeleteConfig(IDirectInputJoyConfig8
*iface
, UINT id
)
1227 FIXME( "(%p)->(%d): stub!\n", iface
, id
);
1231 static HRESULT WINAPI
JoyConfig8Impl_GetUserValues(IDirectInputJoyConfig8
*iface
, LPDIJOYUSERVALUES info
, DWORD flags
)
1233 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1237 static HRESULT WINAPI
JoyConfig8Impl_SetUserValues(IDirectInputJoyConfig8
*iface
, LPCDIJOYUSERVALUES info
, DWORD flags
)
1239 FIXME( "(%p)->(%p, 0x%08x): stub!\n", iface
, info
, flags
);
1243 static HRESULT WINAPI
JoyConfig8Impl_AddNewHardware(IDirectInputJoyConfig8
*iface
, HWND hwnd
, REFGUID guid
)
1245 FIXME( "(%p)->(%p, %s): stub!\n", iface
, hwnd
, debugstr_guid(guid
) );
1249 static HRESULT WINAPI
JoyConfig8Impl_OpenTypeKey(IDirectInputJoyConfig8
*iface
, LPCWSTR name
, DWORD security
, PHKEY key
)
1251 FIXME( "(%p)->(%s, 0x%08x, %p): stub!\n", iface
, debugstr_w(name
), security
, key
);
1255 static HRESULT WINAPI
JoyConfig8Impl_OpenAppStatusKey(IDirectInputJoyConfig8
*iface
, PHKEY key
)
1257 FIXME( "(%p)->(%p): stub!\n", iface
, key
);
1261 static const IDirectInput7AVtbl ddi7avt
= {
1262 IDirectInputAImpl_QueryInterface
,
1263 IDirectInputAImpl_AddRef
,
1264 IDirectInputAImpl_Release
,
1265 IDirectInputAImpl_CreateDevice
,
1266 IDirectInputAImpl_EnumDevices
,
1267 IDirectInputAImpl_GetDeviceStatus
,
1268 IDirectInputAImpl_RunControlPanel
,
1269 IDirectInputAImpl_Initialize
,
1270 IDirectInput2AImpl_FindDevice
,
1271 IDirectInput7AImpl_CreateDeviceEx
1274 static const IDirectInput7WVtbl ddi7wvt
= {
1275 IDirectInputWImpl_QueryInterface
,
1276 IDirectInputWImpl_AddRef
,
1277 IDirectInputWImpl_Release
,
1278 IDirectInputWImpl_CreateDevice
,
1279 IDirectInputWImpl_EnumDevices
,
1280 IDirectInputWImpl_GetDeviceStatus
,
1281 IDirectInputWImpl_RunControlPanel
,
1282 IDirectInputWImpl_Initialize
,
1283 IDirectInput2WImpl_FindDevice
,
1284 IDirectInput7WImpl_CreateDeviceEx
1287 static const IDirectInput8AVtbl ddi8avt
= {
1288 IDirectInput8AImpl_QueryInterface
,
1289 IDirectInput8AImpl_AddRef
,
1290 IDirectInput8AImpl_Release
,
1291 IDirectInput8AImpl_CreateDevice
,
1292 IDirectInput8AImpl_EnumDevices
,
1293 IDirectInput8AImpl_GetDeviceStatus
,
1294 IDirectInput8AImpl_RunControlPanel
,
1295 IDirectInput8AImpl_Initialize
,
1296 IDirectInput8AImpl_FindDevice
,
1297 IDirectInput8AImpl_EnumDevicesBySemantics
,
1298 IDirectInput8AImpl_ConfigureDevices
1301 static const IDirectInput8WVtbl ddi8wvt
= {
1302 IDirectInput8WImpl_QueryInterface
,
1303 IDirectInput8WImpl_AddRef
,
1304 IDirectInput8WImpl_Release
,
1305 IDirectInput8WImpl_CreateDevice
,
1306 IDirectInput8WImpl_EnumDevices
,
1307 IDirectInput8WImpl_GetDeviceStatus
,
1308 IDirectInput8WImpl_RunControlPanel
,
1309 IDirectInput8WImpl_Initialize
,
1310 IDirectInput8WImpl_FindDevice
,
1311 IDirectInput8WImpl_EnumDevicesBySemantics
,
1312 IDirectInput8WImpl_ConfigureDevices
1315 static const IDirectInputJoyConfig8Vtbl JoyConfig8vt
=
1317 JoyConfig8Impl_QueryInterface
,
1318 JoyConfig8Impl_AddRef
,
1319 JoyConfig8Impl_Release
,
1320 JoyConfig8Impl_Acquire
,
1321 JoyConfig8Impl_Unacquire
,
1322 JoyConfig8Impl_SetCooperativeLevel
,
1323 JoyConfig8Impl_SendNotify
,
1324 JoyConfig8Impl_EnumTypes
,
1325 JoyConfig8Impl_GetTypeInfo
,
1326 JoyConfig8Impl_SetTypeInfo
,
1327 JoyConfig8Impl_DeleteType
,
1328 JoyConfig8Impl_GetConfig
,
1329 JoyConfig8Impl_SetConfig
,
1330 JoyConfig8Impl_DeleteConfig
,
1331 JoyConfig8Impl_GetUserValues
,
1332 JoyConfig8Impl_SetUserValues
,
1333 JoyConfig8Impl_AddNewHardware
,
1334 JoyConfig8Impl_OpenTypeKey
,
1335 JoyConfig8Impl_OpenAppStatusKey
1338 /*******************************************************************************
1339 * DirectInput ClassFactory
1343 /* IUnknown fields */
1344 IClassFactory IClassFactory_iface
;
1346 } IClassFactoryImpl
;
1348 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
1350 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
1353 static HRESULT WINAPI
DICF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
1354 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1356 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
1357 return E_NOINTERFACE
;
1360 static ULONG WINAPI
DICF_AddRef(LPCLASSFACTORY iface
) {
1361 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1362 return InterlockedIncrement(&(This
->ref
));
1365 static ULONG WINAPI
DICF_Release(LPCLASSFACTORY iface
) {
1366 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1367 /* static class, won't be freed */
1368 return InterlockedDecrement(&(This
->ref
));
1371 static HRESULT WINAPI
DICF_CreateInstance(
1372 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
1374 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1376 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1377 if ( IsEqualGUID( &IID_IUnknown
, riid
) ||
1378 IsEqualGUID( &IID_IDirectInputA
, riid
) ||
1379 IsEqualGUID( &IID_IDirectInputW
, riid
) ||
1380 IsEqualGUID( &IID_IDirectInput2A
, riid
) ||
1381 IsEqualGUID( &IID_IDirectInput2W
, riid
) ||
1382 IsEqualGUID( &IID_IDirectInput7A
, riid
) ||
1383 IsEqualGUID( &IID_IDirectInput7W
, riid
) ) {
1384 return create_directinput_instance(riid
, ppobj
, NULL
);
1387 FIXME("(%p,%p,%s,%p) Interface not found!\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1388 return E_NOINTERFACE
;
1391 static HRESULT WINAPI
DICF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
1392 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1393 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
1397 static const IClassFactoryVtbl DICF_Vtbl
= {
1398 DICF_QueryInterface
,
1401 DICF_CreateInstance
,
1404 static IClassFactoryImpl DINPUT_CF
= {{&DICF_Vtbl
}, 1 };
1406 /***********************************************************************
1407 * DllCanUnloadNow (DINPUT.@)
1409 HRESULT WINAPI
DllCanUnloadNow(void)
1414 /***********************************************************************
1415 * DllGetClassObject (DINPUT.@)
1417 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1419 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1420 if ( IsEqualCLSID( &IID_IClassFactory
, riid
) ) {
1422 IClassFactory_AddRef((IClassFactory
*)*ppv
);
1426 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1427 return CLASS_E_CLASSNOTAVAILABLE
;
1430 /***********************************************************************
1431 * DllRegisterServer (DINPUT.@)
1433 HRESULT WINAPI
DllRegisterServer(void)
1435 return __wine_register_resources( DINPUT_instance
);
1438 /***********************************************************************
1439 * DllUnregisterServer (DINPUT.@)
1441 HRESULT WINAPI
DllUnregisterServer(void)
1443 return __wine_unregister_resources( DINPUT_instance
);
1446 /******************************************************************************
1447 * DInput hook thread
1450 static LRESULT CALLBACK
LL_hook_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1452 IDirectInputImpl
*dinput
;
1455 if (code
!= HC_ACTION
) return CallNextHookEx( 0, code
, wparam
, lparam
);
1457 EnterCriticalSection( &dinput_hook_crit
);
1458 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1460 IDirectInputDeviceImpl
*dev
;
1462 EnterCriticalSection( &dinput
->crit
);
1463 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1464 if (dev
->acquired
&& dev
->event_proc
)
1466 TRACE("calling %p->%p (%lx %lx)\n", dev
, dev
->event_proc
, wparam
, lparam
);
1467 skip
|= dev
->event_proc( &dev
->IDirectInputDevice8A_iface
, wparam
, lparam
);
1469 LeaveCriticalSection( &dinput
->crit
);
1471 LeaveCriticalSection( &dinput_hook_crit
);
1473 return skip
? 1 : CallNextHookEx( 0, code
, wparam
, lparam
);
1476 static LRESULT CALLBACK
callwndproc_proc( int code
, WPARAM wparam
, LPARAM lparam
)
1478 CWPSTRUCT
*msg
= (CWPSTRUCT
*)lparam
;
1479 IDirectInputImpl
*dinput
;
1482 if (code
!= HC_ACTION
|| (msg
->message
!= WM_KILLFOCUS
&&
1483 msg
->message
!= WM_ACTIVATEAPP
&& msg
->message
!= WM_ACTIVATE
))
1484 return CallNextHookEx( 0, code
, wparam
, lparam
);
1486 foreground
= GetForegroundWindow();
1488 EnterCriticalSection( &dinput_hook_crit
);
1490 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1492 IDirectInputDeviceImpl
*dev
;
1494 EnterCriticalSection( &dinput
->crit
);
1495 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1497 if (!dev
->acquired
) continue;
1499 if (msg
->hwnd
== dev
->win
&& msg
->hwnd
!= foreground
)
1501 TRACE( "%p window is not foreground - unacquiring %p\n", dev
->win
, dev
);
1502 IDirectInputDevice_Unacquire( &dev
->IDirectInputDevice8A_iface
);
1505 LeaveCriticalSection( &dinput
->crit
);
1507 LeaveCriticalSection( &dinput_hook_crit
);
1509 return CallNextHookEx( 0, code
, wparam
, lparam
);
1512 static DWORD WINAPI
hook_thread_proc(void *param
)
1514 static HHOOK kbd_hook
, mouse_hook
;
1517 /* Force creation of the message queue */
1518 PeekMessageW( &msg
, 0, 0, 0, PM_NOREMOVE
);
1519 SetEvent(*(LPHANDLE
)param
);
1521 while (GetMessageW( &msg
, 0, 0, 0 ))
1523 UINT kbd_cnt
= 0, mice_cnt
= 0;
1525 if (msg
.message
== WM_USER
+0x10)
1527 IDirectInputImpl
*dinput
;
1529 TRACE( "Processing hook change notification lp:%ld\n", msg
.lParam
);
1531 if (!msg
.wParam
&& !msg
.lParam
)
1533 if (kbd_hook
) UnhookWindowsHookEx( kbd_hook
);
1534 if (mouse_hook
) UnhookWindowsHookEx( mouse_hook
);
1535 kbd_hook
= mouse_hook
= NULL
;
1539 EnterCriticalSection( &dinput_hook_crit
);
1541 /* Count acquired keyboards and mice*/
1542 LIST_FOR_EACH_ENTRY( dinput
, &direct_input_list
, IDirectInputImpl
, entry
)
1544 IDirectInputDeviceImpl
*dev
;
1546 EnterCriticalSection( &dinput
->crit
);
1547 LIST_FOR_EACH_ENTRY( dev
, &dinput
->devices_list
, IDirectInputDeviceImpl
, entry
)
1549 if (!dev
->acquired
|| !dev
->event_proc
) continue;
1551 if (IsEqualGUID( &dev
->guid
, &GUID_SysKeyboard
) ||
1552 IsEqualGUID( &dev
->guid
, &DInput_Wine_Keyboard_GUID
))
1555 if (IsEqualGUID( &dev
->guid
, &GUID_SysMouse
) ||
1556 IsEqualGUID( &dev
->guid
, &DInput_Wine_Mouse_GUID
))
1559 LeaveCriticalSection( &dinput
->crit
);
1561 LeaveCriticalSection( &dinput_hook_crit
);
1563 if (kbd_cnt
&& !kbd_hook
)
1564 kbd_hook
= SetWindowsHookExW( WH_KEYBOARD_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1565 else if (!kbd_cnt
&& kbd_hook
)
1567 UnhookWindowsHookEx( kbd_hook
);
1571 if (mice_cnt
&& !mouse_hook
)
1572 mouse_hook
= SetWindowsHookExW( WH_MOUSE_LL
, LL_hook_proc
, DINPUT_instance
, 0 );
1573 else if (!mice_cnt
&& mouse_hook
)
1575 UnhookWindowsHookEx( mouse_hook
);
1579 TranslateMessage(&msg
);
1580 DispatchMessageW(&msg
);
1586 static DWORD hook_thread_id
;
1588 static CRITICAL_SECTION_DEBUG dinput_critsect_debug
=
1590 0, 0, &dinput_hook_crit
,
1591 { &dinput_critsect_debug
.ProcessLocksList
, &dinput_critsect_debug
.ProcessLocksList
},
1592 0, 0, { (DWORD_PTR
)(__FILE__
": dinput_hook_crit") }
1594 static CRITICAL_SECTION dinput_hook_crit
= { &dinput_critsect_debug
, -1, 0, 0, 0, 0 };
1596 static BOOL
check_hook_thread(void)
1598 static HANDLE hook_thread
;
1600 EnterCriticalSection(&dinput_hook_crit
);
1602 TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list
));
1603 if (!list_empty(&direct_input_list
) && !hook_thread
)
1607 event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1608 hook_thread
= CreateThread(NULL
, 0, hook_thread_proc
, &event
, 0, &hook_thread_id
);
1609 if (event
&& hook_thread
)
1613 handles
[1] = hook_thread
;
1614 WaitForMultipleObjects(2, handles
, FALSE
, INFINITE
);
1616 LeaveCriticalSection(&dinput_hook_crit
);
1619 else if (list_empty(&direct_input_list
) && hook_thread
)
1621 DWORD tid
= hook_thread_id
;
1624 PostThreadMessageW(tid
, WM_USER
+0x10, 0, 0);
1625 LeaveCriticalSection(&dinput_hook_crit
);
1627 /* wait for hook thread to exit */
1628 WaitForSingleObject(hook_thread
, INFINITE
);
1629 CloseHandle(hook_thread
);
1633 LeaveCriticalSection(&dinput_hook_crit
);
1635 return hook_thread_id
!= 0;
1638 void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface
)
1640 static HHOOK callwndproc_hook
;
1641 static ULONG foreground_cnt
;
1642 IDirectInputDeviceImpl
*dev
= impl_from_IDirectInputDevice8W(iface
);
1644 EnterCriticalSection(&dinput_hook_crit
);
1646 if (dev
->dwCoopLevel
& DISCL_FOREGROUND
)
1654 if (foreground_cnt
&& !callwndproc_hook
)
1655 callwndproc_hook
= SetWindowsHookExW( WH_CALLWNDPROC
, callwndproc_proc
,
1656 DINPUT_instance
, GetCurrentThreadId() );
1657 else if (!foreground_cnt
&& callwndproc_hook
)
1659 UnhookWindowsHookEx( callwndproc_hook
);
1660 callwndproc_hook
= NULL
;
1663 PostThreadMessageW( hook_thread_id
, WM_USER
+0x10, 1, 0 );
1665 LeaveCriticalSection(&dinput_hook_crit
);
1668 void check_dinput_events(void)
1670 /* Windows does not do that, but our current implementation of winex11
1671 * requires periodic event polling to forward events to the wineserver.
1673 * We have to call this function from multiple places, because:
1674 * - some games do not explicitly poll for mouse events
1675 * (for example Culpa Innata)
1676 * - some games only poll the device, and neither keyboard nor mouse
1677 * (for example Civilization: Call to Power 2)
1679 MsgWaitForMultipleObjectsEx(0, NULL
, 0, QS_ALLINPUT
, 0);
1682 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
1686 case DLL_PROCESS_ATTACH
:
1687 DisableThreadLibraryCalls(inst
);
1688 DINPUT_instance
= inst
;
1690 case DLL_PROCESS_DETACH
:
1691 if (reserved
) break;
1692 DeleteCriticalSection(&dinput_hook_crit
);