3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 /* This file contains all the Device specific functions that can be used as stubs
23 by real device implementations.
25 It also contains all the helper functions.
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
38 #include "device_private.h"
39 #include "dinput_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
43 /******************************************************************************
44 * Various debugging tools
46 void _dump_cooperativelevel_DI(DWORD dwFlags
) {
47 if (TRACE_ON(dinput
)) {
53 #define FE(x) { x, #x}
57 FE(DISCL_NONEXCLUSIVE
),
61 for (i
= 0; i
< (sizeof(flags
) / sizeof(flags
[0])); i
++)
62 if (flags
[i
].mask
& dwFlags
)
63 DPRINTF("%s ",flags
[i
].name
);
68 void _dump_EnumObjects_flags(DWORD dwFlags
) {
69 if (TRACE_ON(dinput
)) {
76 #define FE(x) { x, #x}
85 FE(DIDFT_FFEFFECTTRIGGER
),
87 FE(DIDFT_VENDORDEFINED
),
92 type
= (dwFlags
& 0xFF0000FF);
93 instance
= ((dwFlags
>> 8) & 0xFFFF);
95 if (type
== DIDFT_ALL
) {
96 DPRINTF(" DIDFT_ALL");
98 for (i
= 0; i
< (sizeof(flags
) / sizeof(flags
[0])); i
++) {
99 if (flags
[i
].mask
& type
) {
100 type
&= ~flags
[i
].mask
;
101 DPRINTF(" %s",flags
[i
].name
);
105 DPRINTF(" (unhandled: %08x)", type
);
108 DPRINTF(" / Instance: ");
109 if (instance
== ((DIDFT_ANYINSTANCE
>> 8) & 0xFFFF)) {
110 DPRINTF("DIDFT_ANYINSTANCE");
112 DPRINTF("%3d", instance
);
117 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph
) {
118 if (TRACE_ON(dinput
)) {
119 DPRINTF(" - dwObj = 0x%08x\n", diph
->dwObj
);
120 DPRINTF(" - dwHow = %s\n",
121 ((diph
->dwHow
== DIPH_DEVICE
) ? "DIPH_DEVICE" :
122 ((diph
->dwHow
== DIPH_BYOFFSET
) ? "DIPH_BYOFFSET" :
123 ((diph
->dwHow
== DIPH_BYID
)) ? "DIPH_BYID" : "unknown")));
127 void _dump_OBJECTINSTANCEA(DIDEVICEOBJECTINSTANCEA
*ddoi
) {
128 if (TRACE_ON(dinput
)) {
129 DPRINTF(" - enumerating : %s ('%s') - %2d - 0x%08x - %s\n",
130 debugstr_guid(&ddoi
->guidType
), _dump_dinput_GUID(&ddoi
->guidType
), ddoi
->dwOfs
, ddoi
->dwType
, ddoi
->tszName
);
134 void _dump_OBJECTINSTANCEW(DIDEVICEOBJECTINSTANCEW
*ddoi
) {
135 if (TRACE_ON(dinput
)) {
136 DPRINTF(" - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
137 debugstr_guid(&ddoi
->guidType
), _dump_dinput_GUID(&ddoi
->guidType
), ddoi
->dwOfs
, ddoi
->dwType
, debugstr_w(ddoi
->tszName
));
141 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
142 const char *_dump_dinput_GUID(const GUID
*guid
) {
144 static const struct {
148 #define FE(x) { &x, #x}
161 FE(GUID_SysKeyboard
),
163 FE(GUID_ConstantForce
),
169 FE(GUID_SawtoothDown
),
179 for (i
= 0; i
< (sizeof(guids
) / sizeof(guids
[0])); i
++) {
180 if (IsEqualGUID(guids
[i
].guid
, guid
)) {
181 return guids
[i
].name
;
184 return "Unknown GUID";
187 void _dump_DIDATAFORMAT(const DIDATAFORMAT
*df
) {
190 TRACE("Dumping DIDATAFORMAT structure:\n");
191 TRACE(" - dwSize: %d\n", df
->dwSize
);
192 if (df
->dwSize
!= sizeof(DIDATAFORMAT
)) {
193 WARN("Non-standard DIDATAFORMAT structure size %d\n", df
->dwSize
);
195 TRACE(" - dwObjsize: %d\n", df
->dwObjSize
);
196 if (df
->dwObjSize
!= sizeof(DIOBJECTDATAFORMAT
)) {
197 WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df
->dwObjSize
);
199 TRACE(" - dwFlags: 0x%08x (", df
->dwFlags
);
200 switch (df
->dwFlags
) {
201 case DIDF_ABSAXIS
: TRACE("DIDF_ABSAXIS"); break;
202 case DIDF_RELAXIS
: TRACE("DIDF_RELAXIS"); break;
203 default: TRACE("unknown"); break;
206 TRACE(" - dwDataSize: %d\n", df
->dwDataSize
);
207 TRACE(" - dwNumObjs: %d\n", df
->dwNumObjs
);
209 for (i
= 0; i
< df
->dwNumObjs
; i
++) {
210 TRACE(" - Object %d:\n", i
);
211 TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df
->rgodf
[i
].pguid
), _dump_dinput_GUID(df
->rgodf
[i
].pguid
));
212 TRACE(" * dwOfs: %d\n", df
->rgodf
[i
].dwOfs
);
213 TRACE(" * dwType: 0x%08x\n", df
->rgodf
[i
].dwType
);
214 TRACE(" "); _dump_EnumObjects_flags(df
->rgodf
[i
].dwType
); TRACE("\n");
215 TRACE(" * dwFlags: 0x%08x\n", df
->rgodf
[i
].dwFlags
);
219 /* Conversion between internal data buffer and external data buffer */
220 void fill_DataFormat(void *out
, const void *in
, DataFormat
*df
) {
222 const char *in_c
= in
;
223 char *out_c
= (char *) out
;
225 if (df
->dt
== NULL
) {
226 /* This means that the app uses Wine's internal data format */
227 memcpy(out
, in
, df
->internal_format_size
);
229 for (i
= 0; i
< df
->size
; i
++) {
230 if (df
->dt
[i
].offset_in
>= 0) {
231 switch (df
->dt
[i
].size
) {
233 TRACE("Copying (c) to %d from %d (value %d)\n",
234 df
->dt
[i
].offset_out
, df
->dt
[i
].offset_in
, *(in_c
+ df
->dt
[i
].offset_in
));
235 *(out_c
+ df
->dt
[i
].offset_out
) = *(in_c
+ df
->dt
[i
].offset_in
);
239 TRACE("Copying (s) to %d from %d (value %d)\n",
240 df
->dt
[i
].offset_out
, df
->dt
[i
].offset_in
, *((const short *)(in_c
+ df
->dt
[i
].offset_in
)));
241 *((short *)(out_c
+ df
->dt
[i
].offset_out
)) = *((const short *)(in_c
+ df
->dt
[i
].offset_in
));
245 TRACE("Copying (i) to %d from %d (value %d)\n",
246 df
->dt
[i
].offset_out
, df
->dt
[i
].offset_in
, *((const int *)(in_c
+ df
->dt
[i
].offset_in
)));
247 *((int *)(out_c
+ df
->dt
[i
].offset_out
)) = *((const int *)(in_c
+ df
->dt
[i
].offset_in
));
251 memcpy((out_c
+ df
->dt
[i
].offset_out
), (in_c
+ df
->dt
[i
].offset_in
), df
->dt
[i
].size
);
255 switch (df
->dt
[i
].size
) {
257 TRACE("Copying (c) to %d default value %d\n",
258 df
->dt
[i
].offset_out
, df
->dt
[i
].value
);
259 *(out_c
+ df
->dt
[i
].offset_out
) = (char) df
->dt
[i
].value
;
263 TRACE("Copying (s) to %d default value %d\n",
264 df
->dt
[i
].offset_out
, df
->dt
[i
].value
);
265 *((short *) (out_c
+ df
->dt
[i
].offset_out
)) = (short) df
->dt
[i
].value
;
269 TRACE("Copying (i) to %d default value %d\n",
270 df
->dt
[i
].offset_out
, df
->dt
[i
].value
);
271 *((int *) (out_c
+ df
->dt
[i
].offset_out
)) = (int) df
->dt
[i
].value
;
275 memset((out_c
+ df
->dt
[i
].offset_out
), 0, df
->dt
[i
].size
);
283 void release_DataFormat(DataFormat
* format
)
285 TRACE("Deleting DataTransform :\n");
287 HeapFree(GetProcessHeap(), 0, format
->dt
);
290 /* Make all instances sequential */
291 static void calculate_ids(LPDIDATAFORMAT df
)
293 int i
, axis
= 0, pov
= 0, button
= 0;
294 int axis_base
, pov_base
, button_base
;
297 /* Make two passes over the format. The first counts the number
298 * for each type and the second sets the id */
299 for (i
= 0; i
< df
->dwNumObjs
; i
++)
301 type
= DIDFT_GETTYPE(df
->rgodf
[i
].dwType
);
302 if (type
& DIDFT_AXIS
) axis
++;
303 else if (type
& DIDFT_POV
) pov
++;
304 else if (type
& DIDFT_BUTTON
) button
++;
308 pov_base
= axis_base
+ axis
;
309 button_base
= pov_base
+ pov
;
310 axis
= pov
= button
= 0;
312 for (i
= 0; i
< df
->dwNumObjs
; i
++)
314 type
= DIDFT_GETTYPE(df
->rgodf
[i
].dwType
);
315 if (type
& DIDFT_AXIS
)
317 type
|= DIDFT_MAKEINSTANCE(axis_base
+ axis
++);
318 TRACE("axis type = 0x%08x\n", type
);
319 } else if (type
& DIDFT_POV
)
321 type
|= DIDFT_MAKEINSTANCE(pov_base
+ pov
++);
322 TRACE("POV type = 0x%08x\n", type
);
323 } else if (type
& DIDFT_BUTTON
)
325 type
|= DIDFT_MAKEINSTANCE(button_base
+ button
++);
326 TRACE("button type = 0x%08x\n", type
);
328 df
->rgodf
[i
].dwType
= type
;
332 DataFormat
*create_DataFormat(LPCDIDATAFORMAT wine_format
, LPDIDATAFORMAT asked_format
, int *offset
)
342 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat
));
344 done
= HeapAlloc(GetProcessHeap(), 0, sizeof(int) * asked_format
->dwNumObjs
);
345 memset(done
, 0, sizeof(int) * asked_format
->dwNumObjs
);
347 dt
= HeapAlloc(GetProcessHeap(), 0, asked_format
->dwNumObjs
* sizeof(DataTransform
));
349 TRACE("Creating DataTransform :\n");
351 for (i
= 0; i
< wine_format
->dwNumObjs
; i
++) {
354 for (j
= 0; j
< asked_format
->dwNumObjs
; j
++) {
358 if (/* Check if the application either requests any GUID and if not, it if matches
359 * the GUID of the Wine object.
361 ((asked_format
->rgodf
[j
].pguid
== NULL
) ||
362 (wine_format
->rgodf
[i
].pguid
== NULL
) ||
363 (IsEqualGUID(wine_format
->rgodf
[i
].pguid
, asked_format
->rgodf
[j
].pguid
)))
365 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
368 (DIDFT_GETINSTANCE(asked_format
->rgodf
[j
].dwType
) == 0xFFFF) ||
369 (DIDFT_GETINSTANCE(asked_format
->rgodf
[j
].dwType
) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
370 (DIDFT_GETINSTANCE(asked_format
->rgodf
[j
].dwType
) == DIDFT_GETINSTANCE(wine_format
->rgodf
[i
].dwType
)))
372 ( /* Then if the asked type matches the one Wine provides */
373 DIDFT_GETTYPE(asked_format
->rgodf
[j
].dwType
) & wine_format
->rgodf
[i
].dwType
))
377 TRACE("Matching :\n");
378 TRACE(" - Asked (%d) :\n", j
);
379 TRACE(" * GUID: %s ('%s')\n",
380 debugstr_guid(asked_format
->rgodf
[j
].pguid
),
381 _dump_dinput_GUID(asked_format
->rgodf
[j
].pguid
));
382 TRACE(" * Offset: %3d\n", asked_format
->rgodf
[j
].dwOfs
);
383 TRACE(" * dwType: %08x\n", asked_format
->rgodf
[j
].dwType
);
384 TRACE(" "); _dump_EnumObjects_flags(asked_format
->rgodf
[j
].dwType
); TRACE("\n");
386 TRACE(" - Wine (%d) :\n", i
);
387 TRACE(" * GUID: %s ('%s')\n",
388 debugstr_guid(wine_format
->rgodf
[i
].pguid
),
389 _dump_dinput_GUID(wine_format
->rgodf
[i
].pguid
));
390 TRACE(" * Offset: %3d\n", wine_format
->rgodf
[i
].dwOfs
);
391 TRACE(" * dwType: %08x\n", wine_format
->rgodf
[i
].dwType
);
392 TRACE(" "); _dump_EnumObjects_flags(wine_format
->rgodf
[i
].dwType
); TRACE("\n");
394 if (wine_format
->rgodf
[i
].dwType
& DIDFT_BUTTON
)
395 dt
[index
].size
= sizeof(BYTE
);
397 dt
[index
].size
= sizeof(DWORD
);
398 dt
[index
].offset_in
= wine_format
->rgodf
[i
].dwOfs
;
399 dt
[index
].offset_out
= asked_format
->rgodf
[j
].dwOfs
;
400 offset
[i
] = asked_format
->rgodf
[j
].dwOfs
;
402 next
= next
+ dt
[index
].size
;
404 if (wine_format
->rgodf
[i
].dwOfs
!= dt
[index
].offset_out
)
412 if (j
== asked_format
->dwNumObjs
)
416 TRACE("Setting to default value :\n");
417 for (j
= 0; j
< asked_format
->dwNumObjs
; j
++) {
419 TRACE(" - Asked (%d) :\n", j
);
420 TRACE(" * GUID: %s ('%s')\n",
421 debugstr_guid(asked_format
->rgodf
[j
].pguid
),
422 _dump_dinput_GUID(asked_format
->rgodf
[j
].pguid
));
423 TRACE(" * Offset: %3d\n", asked_format
->rgodf
[j
].dwOfs
);
424 TRACE(" * dwType: %08x\n", asked_format
->rgodf
[j
].dwType
);
425 TRACE(" "); _dump_EnumObjects_flags(asked_format
->rgodf
[j
].dwType
); TRACE("\n");
427 if (asked_format
->rgodf
[j
].dwType
& DIDFT_BUTTON
)
428 dt
[index
].size
= sizeof(BYTE
);
430 dt
[index
].size
= sizeof(DWORD
);
431 dt
[index
].offset_in
= -1;
432 dt
[index
].offset_out
= asked_format
->rgodf
[j
].dwOfs
;
440 ret
->internal_format_size
= wine_format
->dwDataSize
;
444 HeapFree(GetProcessHeap(), 0, dt
);
449 HeapFree(GetProcessHeap(), 0, done
);
451 /* Last step - reset all instances of the new format */
452 calculate_ids(asked_format
);
456 BOOL
DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi
, LPVOID lpvRef
) {
457 DIDEVICEOBJECTINSTANCEW ddtmp
;
458 device_enumobjects_AtoWcb_data
* data
;
460 data
= (device_enumobjects_AtoWcb_data
*) lpvRef
;
462 memset(&ddtmp
, 0, sizeof(ddtmp
));
464 ddtmp
.dwSize
= sizeof(DIDEVICEINSTANCEW
);
465 ddtmp
.guidType
= lpddi
->guidType
;
466 ddtmp
.dwOfs
= lpddi
->dwOfs
;
467 ddtmp
.dwType
= lpddi
->dwType
;
468 ddtmp
.dwFlags
= lpddi
->dwFlags
;
469 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszName
, -1, ddtmp
.tszName
, MAX_PATH
);
471 if (lpddi
->dwSize
== sizeof(DIDEVICEINSTANCEA
)) {
473 * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
474 * force feedback and other newer datas aren't available
476 ddtmp
.dwFFMaxForce
= lpddi
->dwFFMaxForce
;
477 ddtmp
.dwFFForceResolution
= lpddi
->dwFFForceResolution
;
478 ddtmp
.wCollectionNumber
= lpddi
->wCollectionNumber
;
479 ddtmp
.wDesignatorIndex
= lpddi
->wDesignatorIndex
;
480 ddtmp
.wUsagePage
= lpddi
->wUsagePage
;
481 ddtmp
.wUsage
= lpddi
->wUsage
;
482 ddtmp
.dwDimension
= lpddi
->dwDimension
;
483 ddtmp
.wExponent
= lpddi
->wExponent
;
484 ddtmp
.wReserved
= lpddi
->wReserved
;
486 return data
->lpCallBack(&ddtmp
, data
->lpvRef
);
489 /******************************************************************************
490 * queue_event - add new event to the ring queue
493 void queue_event(LPDIRECTINPUTDEVICE8A iface
, int ofs
, DWORD data
, DWORD time
, DWORD seq
)
495 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
498 if (!This
->queue_len
|| This
->overflow
|| ofs
< 0) return;
500 next_pos
= (This
->queue_head
+ 1) % This
->queue_len
;
501 if (next_pos
== This
->queue_tail
)
503 TRACE(" queue overflowed\n");
504 This
->overflow
= TRUE
;
508 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
509 data
, ofs
, This
->queue_head
, This
->queue_len
);
511 This
->data_queue
[This
->queue_head
].dwOfs
= ofs
;
512 This
->data_queue
[This
->queue_head
].dwData
= data
;
513 This
->data_queue
[This
->queue_head
].dwTimeStamp
= time
;
514 This
->data_queue
[This
->queue_head
].dwSequence
= seq
;
515 This
->queue_head
= next_pos
;
518 /******************************************************************************
522 HRESULT WINAPI
IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
524 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
527 EnterCriticalSection(&This
->crit
);
528 res
= This
->acquired
? S_FALSE
: DI_OK
;
531 This
->queue_head
= This
->queue_tail
= This
->overflow
= 0;
532 LeaveCriticalSection(&This
->crit
);
537 /******************************************************************************
541 HRESULT WINAPI
IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
543 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
546 EnterCriticalSection(&This
->crit
);
547 res
= !This
->acquired
? DI_NOEFFECT
: DI_OK
;
549 LeaveCriticalSection(&This
->crit
);
554 /******************************************************************************
555 * IDirectInputDeviceA
558 HRESULT WINAPI
IDirectInputDevice2AImpl_SetDataFormat(
559 LPDIRECTINPUTDEVICE8A iface
,LPCDIDATAFORMAT df
561 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
563 TRACE("(this=%p,%p)\n",This
,df
);
565 _dump_DIDATAFORMAT(df
);
570 /******************************************************************************
571 * SetCooperativeLevel
573 * Set cooperative level and the source window for the events.
575 HRESULT WINAPI
IDirectInputDevice2AImpl_SetCooperativeLevel(
576 LPDIRECTINPUTDEVICE8A iface
, HWND hwnd
, DWORD dwflags
)
578 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
580 TRACE("(%p) %p,0x%08x\n", This
, hwnd
, dwflags
);
581 TRACE(" cooperative level : ");
582 _dump_cooperativelevel_DI(dwflags
);
584 if ((dwflags
& (DISCL_EXCLUSIVE
| DISCL_NONEXCLUSIVE
)) == 0 ||
585 (dwflags
& (DISCL_EXCLUSIVE
| DISCL_NONEXCLUSIVE
)) == (DISCL_EXCLUSIVE
| DISCL_NONEXCLUSIVE
) ||
586 (dwflags
& (DISCL_FOREGROUND
| DISCL_BACKGROUND
)) == 0 ||
587 (dwflags
& (DISCL_FOREGROUND
| DISCL_BACKGROUND
)) == (DISCL_FOREGROUND
| DISCL_BACKGROUND
))
588 return DIERR_INVALIDPARAM
;
590 if (dwflags
== (DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
))
591 hwnd
= GetDesktopWindow();
593 if (!hwnd
) return E_HANDLE
;
595 /* For security reasons native does not allow exclusive background level
596 for mouse and keyboard only */
597 if (dwflags
& DISCL_EXCLUSIVE
&& dwflags
& DISCL_BACKGROUND
&&
598 (IsEqualGUID(&This
->guid
, &GUID_SysMouse
) ||
599 IsEqualGUID(&This
->guid
, &GUID_SysKeyboard
)))
600 return DIERR_UNSUPPORTED
;
602 /* Store the window which asks for the mouse */
603 EnterCriticalSection(&This
->crit
);
605 This
->dwCoopLevel
= dwflags
;
606 LeaveCriticalSection(&This
->crit
);
611 /******************************************************************************
612 * SetEventNotification : specifies event to be sent on state change
614 HRESULT WINAPI
IDirectInputDevice2AImpl_SetEventNotification(
615 LPDIRECTINPUTDEVICE8A iface
, HANDLE event
)
617 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
619 TRACE("(%p) %p\n", This
, event
);
621 EnterCriticalSection(&This
->crit
);
622 This
->hEvent
= event
;
623 LeaveCriticalSection(&This
->crit
);
627 ULONG WINAPI
IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
629 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
632 ref
= InterlockedDecrement(&(This
->ref
));
635 DeleteCriticalSection(&This
->crit
);
636 HeapFree(GetProcessHeap(), 0, This
->data_queue
);
637 HeapFree(GetProcessHeap(), 0, This
);
642 HRESULT WINAPI
IDirectInputDevice2AImpl_QueryInterface(
643 LPDIRECTINPUTDEVICE8A iface
,REFIID riid
,LPVOID
*ppobj
646 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
648 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
649 if (IsEqualGUID(&IID_IUnknown
,riid
)) {
650 IDirectInputDevice2_AddRef(iface
);
654 if (IsEqualGUID(&IID_IDirectInputDeviceA
,riid
)) {
655 IDirectInputDevice2_AddRef(iface
);
659 if (IsEqualGUID(&IID_IDirectInputDevice2A
,riid
)) {
660 IDirectInputDevice2_AddRef(iface
);
664 if (IsEqualGUID(&IID_IDirectInputDevice7A
,riid
)) {
665 IDirectInputDevice7_AddRef(iface
);
669 if (IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
670 IDirectInputDevice8_AddRef(iface
);
674 TRACE("Unsupported interface !\n");
678 HRESULT WINAPI
IDirectInputDevice2WImpl_QueryInterface(
679 LPDIRECTINPUTDEVICE8W iface
,REFIID riid
,LPVOID
*ppobj
682 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
684 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
685 if (IsEqualGUID(&IID_IUnknown
,riid
)) {
686 IDirectInputDevice2_AddRef(iface
);
690 if (IsEqualGUID(&IID_IDirectInputDeviceW
,riid
)) {
691 IDirectInputDevice2_AddRef(iface
);
695 if (IsEqualGUID(&IID_IDirectInputDevice2W
,riid
)) {
696 IDirectInputDevice2_AddRef(iface
);
700 if (IsEqualGUID(&IID_IDirectInputDevice7W
,riid
)) {
701 IDirectInputDevice7_AddRef(iface
);
705 if (IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
706 IDirectInputDevice8_AddRef(iface
);
710 TRACE("Unsupported interface !\n");
714 ULONG WINAPI
IDirectInputDevice2AImpl_AddRef(
715 LPDIRECTINPUTDEVICE8A iface
)
717 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
718 return InterlockedIncrement(&(This
->ref
));
721 HRESULT WINAPI
IDirectInputDevice2AImpl_EnumObjects(
722 LPDIRECTINPUTDEVICE8A iface
,
723 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
727 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface
, lpCallback
, lpvRef
, dwFlags
);
728 if (TRACE_ON(dinput
)) {
729 DPRINTF(" - flags = ");
730 _dump_EnumObjects_flags(dwFlags
);
737 HRESULT WINAPI
IDirectInputDevice2WImpl_EnumObjects(
738 LPDIRECTINPUTDEVICE8W iface
,
739 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
743 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface
, lpCallback
, lpvRef
, dwFlags
);
744 if (TRACE_ON(dinput
)) {
745 DPRINTF(" - flags = ");
746 _dump_EnumObjects_flags(dwFlags
);
753 /******************************************************************************
757 HRESULT WINAPI
IDirectInputDevice2AImpl_GetProperty(
758 LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
760 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
762 TRACE("(%p) %s,%p\n", iface
, debugstr_guid(rguid
), pdiph
);
763 _dump_DIPROPHEADER(pdiph
);
765 if (HIWORD(rguid
)) return DI_OK
;
767 switch (LOWORD(rguid
))
769 case (DWORD
) DIPROP_BUFFERSIZE
:
771 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
773 if (pdiph
->dwSize
!= sizeof(DIPROPDWORD
)) return DIERR_INVALIDPARAM
;
775 pd
->dwData
= This
->queue_len
;
776 TRACE("buffersize = %d\n", pd
->dwData
);
780 WARN("Unknown property %s\n", debugstr_guid(rguid
));
787 /******************************************************************************
791 HRESULT WINAPI
IDirectInputDevice2AImpl_SetProperty(
792 LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPCDIPROPHEADER pdiph
)
794 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
796 TRACE("(%p) %s,%p\n", iface
, debugstr_guid(rguid
), pdiph
);
797 _dump_DIPROPHEADER(pdiph
);
799 if (HIWORD(rguid
)) return DI_OK
;
801 switch (LOWORD(rguid
))
803 case (DWORD
) DIPROP_BUFFERSIZE
:
805 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)pdiph
;
807 if (pdiph
->dwSize
!= sizeof(DIPROPDWORD
)) return DIERR_INVALIDPARAM
;
808 if (This
->acquired
) return DIERR_ACQUIRED
;
810 TRACE("buffersize = %d\n", pd
->dwData
);
812 EnterCriticalSection(&This
->crit
);
813 HeapFree(GetProcessHeap(), 0, This
->data_queue
);
815 This
->data_queue
= !pd
->dwData
? NULL
: HeapAlloc(GetProcessHeap(), 0,
816 pd
->dwData
* sizeof(DIDEVICEOBJECTDATA
));
817 This
->queue_head
= This
->queue_tail
= This
->overflow
= 0;
818 This
->queue_len
= pd
->dwData
;
820 LeaveCriticalSection(&This
->crit
);
824 WARN("Unknown property %s\n", debugstr_guid(rguid
));
825 return DIERR_UNSUPPORTED
;
831 HRESULT WINAPI
IDirectInputDevice2AImpl_GetObjectInfo(
832 LPDIRECTINPUTDEVICE8A iface
,
833 LPDIDEVICEOBJECTINSTANCEA pdidoi
,
837 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
838 iface
, pdidoi
, dwObj
, dwHow
);
843 HRESULT WINAPI
IDirectInputDevice2WImpl_GetObjectInfo(
844 LPDIRECTINPUTDEVICE8W iface
,
845 LPDIDEVICEOBJECTINSTANCEW pdidoi
,
849 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
850 iface
, pdidoi
, dwObj
, dwHow
);
855 HRESULT WINAPI
IDirectInputDevice2AImpl_GetDeviceData(
856 LPDIRECTINPUTDEVICE8A iface
, DWORD dodsize
, LPDIDEVICEOBJECTDATA dod
,
857 LPDWORD entries
, DWORD flags
)
859 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
863 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
864 This
, dod
, entries
, entries
? *entries
: 0, dodsize
, flags
);
867 return DIERR_NOTACQUIRED
;
868 if (!This
->queue_len
)
869 return DIERR_NOTBUFFERED
;
870 if (dodsize
< sizeof(DIDEVICEOBJECTDATA_DX3
))
871 return DIERR_INVALIDPARAM
;
873 IDirectInputDevice2_Poll(iface
);
874 EnterCriticalSection(&This
->crit
);
876 len
= This
->queue_head
- This
->queue_tail
;
877 if (len
< 0) len
+= This
->queue_len
;
879 if ((*entries
!= INFINITE
) && (len
> *entries
)) len
= *entries
;
884 for (i
= 0; i
< len
; i
++)
886 int n
= (This
->queue_tail
+ i
) % This
->queue_len
;
887 memcpy((char *)dod
+ dodsize
* i
, This
->data_queue
+ n
, dodsize
);
893 ret
= DI_BUFFEROVERFLOW
;
895 if (!(flags
& DIGDD_PEEK
))
897 /* Advance reading position */
898 This
->queue_tail
= (This
->queue_tail
+ len
) % This
->queue_len
;
899 This
->overflow
= FALSE
;
902 LeaveCriticalSection(&This
->crit
);
904 TRACE("Returning %d events queued\n", *entries
);
908 HRESULT WINAPI
IDirectInputDevice2AImpl_GetDeviceInfo(
909 LPDIRECTINPUTDEVICE8A iface
,
910 LPDIDEVICEINSTANCEA pdidi
)
912 FIXME("(this=%p,%p): stub!\n",
918 HRESULT WINAPI
IDirectInputDevice2WImpl_GetDeviceInfo(
919 LPDIRECTINPUTDEVICE8W iface
,
920 LPDIDEVICEINSTANCEW pdidi
)
922 FIXME("(this=%p,%p): stub!\n",
928 HRESULT WINAPI
IDirectInputDevice2AImpl_RunControlPanel(
929 LPDIRECTINPUTDEVICE8A iface
,
933 FIXME("(this=%p,%p,0x%08x): stub!\n",
934 iface
, hwndOwner
, dwFlags
);
939 HRESULT WINAPI
IDirectInputDevice2AImpl_Initialize(
940 LPDIRECTINPUTDEVICE8A iface
,
945 FIXME("(this=%p,%p,%d,%s): stub!\n",
946 iface
, hinst
, dwVersion
, debugstr_guid(rguid
));
950 /******************************************************************************
951 * IDirectInputDevice2A
954 HRESULT WINAPI
IDirectInputDevice2AImpl_CreateEffect(
955 LPDIRECTINPUTDEVICE8A iface
,
958 LPDIRECTINPUTEFFECT
*ppdef
,
961 FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
962 iface
, debugstr_guid(rguid
), lpeff
, ppdef
, pUnkOuter
);
966 HRESULT WINAPI
IDirectInputDevice2AImpl_EnumEffects(
967 LPDIRECTINPUTDEVICE8A iface
,
968 LPDIENUMEFFECTSCALLBACKA lpCallback
,
972 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
973 iface
, lpCallback
, lpvRef
, dwFlags
);
978 HRESULT WINAPI
IDirectInputDevice2WImpl_EnumEffects(
979 LPDIRECTINPUTDEVICE8W iface
,
980 LPDIENUMEFFECTSCALLBACKW lpCallback
,
984 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
985 iface
, lpCallback
, lpvRef
, dwFlags
);
990 HRESULT WINAPI
IDirectInputDevice2AImpl_GetEffectInfo(
991 LPDIRECTINPUTDEVICE8A iface
,
992 LPDIEFFECTINFOA lpdei
,
995 FIXME("(this=%p,%p,%s): stub!\n",
996 iface
, lpdei
, debugstr_guid(rguid
));
1000 HRESULT WINAPI
IDirectInputDevice2WImpl_GetEffectInfo(
1001 LPDIRECTINPUTDEVICE8W iface
,
1002 LPDIEFFECTINFOW lpdei
,
1005 FIXME("(this=%p,%p,%s): stub!\n",
1006 iface
, lpdei
, debugstr_guid(rguid
));
1010 HRESULT WINAPI
IDirectInputDevice2AImpl_GetForceFeedbackState(
1011 LPDIRECTINPUTDEVICE8A iface
,
1014 FIXME("(this=%p,%p): stub!\n",
1019 HRESULT WINAPI
IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1020 LPDIRECTINPUTDEVICE8A iface
,
1023 FIXME("(this=%p,0x%08x): stub!\n",
1028 HRESULT WINAPI
IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1029 LPDIRECTINPUTDEVICE8A iface
,
1030 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1034 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1035 iface
, lpCallback
, lpvRef
, dwFlags
);
1039 HRESULT WINAPI
IDirectInputDevice2AImpl_Escape(
1040 LPDIRECTINPUTDEVICE8A iface
,
1041 LPDIEFFESCAPE lpDIEEsc
)
1043 FIXME("(this=%p,%p): stub!\n",
1048 HRESULT WINAPI
IDirectInputDevice2AImpl_Poll(
1049 LPDIRECTINPUTDEVICE8A iface
)
1051 IDirectInputDevice2AImpl
*This
= (IDirectInputDevice2AImpl
*)iface
;
1053 if (!This
->acquired
) return DIERR_NOTACQUIRED
;
1054 /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1058 HRESULT WINAPI
IDirectInputDevice2AImpl_SendDeviceData(
1059 LPDIRECTINPUTDEVICE8A iface
,
1061 LPCDIDEVICEOBJECTDATA rgdod
,
1065 FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1066 iface
, cbObjectData
, rgdod
, pdwInOut
, dwFlags
);
1071 HRESULT WINAPI
IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface
,
1072 LPCSTR lpszFileName
,
1073 LPDIENUMEFFECTSINFILECALLBACK pec
,
1077 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface
, lpszFileName
, pec
, pvRef
, dwFlags
);
1082 HRESULT WINAPI
IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface
,
1083 LPCWSTR lpszFileName
,
1084 LPDIENUMEFFECTSINFILECALLBACK pec
,
1088 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface
, debugstr_w(lpszFileName
), pec
, pvRef
, dwFlags
);
1093 HRESULT WINAPI
IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface
,
1094 LPCSTR lpszFileName
,
1096 LPDIFILEEFFECT rgDiFileEft
,
1099 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface
, lpszFileName
, dwEntries
, rgDiFileEft
, dwFlags
);
1104 HRESULT WINAPI
IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface
,
1105 LPCWSTR lpszFileName
,
1107 LPDIFILEEFFECT rgDiFileEft
,
1110 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface
, debugstr_w(lpszFileName
), dwEntries
, rgDiFileEft
, dwFlags
);
1115 HRESULT WINAPI
IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface
,
1116 LPDIACTIONFORMATA lpdiaf
,
1117 LPCSTR lpszUserName
,
1120 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface
, lpdiaf
, lpszUserName
, dwFlags
);
1125 HRESULT WINAPI
IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface
,
1126 LPDIACTIONFORMATW lpdiaf
,
1127 LPCWSTR lpszUserName
,
1130 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
1135 HRESULT WINAPI
IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface
,
1136 LPDIACTIONFORMATA lpdiaf
,
1137 LPCSTR lpszUserName
,
1140 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface
, lpdiaf
, lpszUserName
, dwFlags
);
1145 HRESULT WINAPI
IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface
,
1146 LPDIACTIONFORMATW lpdiaf
,
1147 LPCWSTR lpszUserName
,
1150 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
1155 HRESULT WINAPI
IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface
,
1156 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader
)
1158 FIXME("(%p)->(%p): stub !\n", iface
, lpdiDevImageInfoHeader
);
1163 HRESULT WINAPI
IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface
,
1164 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader
)
1166 FIXME("(%p)->(%p): stub !\n", iface
, lpdiDevImageInfoHeader
);