dinput: Count should not be 0-based.
[wine] / dlls / dinput / device.c
1 /*              DirectInput Device
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998,1999 Lionel Ulmer
5  *
6  *
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.
11  *
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.
16  *
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
20  */
21
22 /* This file contains all the Device specific functions that can be used as stubs
23    by real device implementations.
24
25    It also contains all the helper functions.
26 */
27 #include "config.h"
28
29 #include <stdarg.h>
30 #include <string.h>
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "winerror.h"
37 #include "dinput.h"
38 #include "device_private.h"
39 #include "dinput_private.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
42
43 /******************************************************************************
44  *      Various debugging tools
45  */
46 void _dump_cooperativelevel_DI(DWORD dwFlags) {
47     if (TRACE_ON(dinput)) {
48         unsigned int   i;
49         static const struct {
50             DWORD       mask;
51             const char  *name;
52         } flags[] = {
53 #define FE(x) { x, #x}
54             FE(DISCL_BACKGROUND),
55             FE(DISCL_EXCLUSIVE),
56             FE(DISCL_FOREGROUND),
57             FE(DISCL_NONEXCLUSIVE),
58             FE(DISCL_NOWINKEY)
59 #undef FE
60         };
61         for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
62             if (flags[i].mask & dwFlags)
63                 DPRINTF("%s ",flags[i].name);
64         DPRINTF("\n");
65     }
66 }
67
68 void _dump_EnumObjects_flags(DWORD dwFlags) {
69     if (TRACE_ON(dinput)) {
70         unsigned int   i;
71         DWORD type, instance;
72         static const struct {
73             DWORD       mask;
74             const char  *name;
75         } flags[] = {
76 #define FE(x) { x, #x}
77             FE(DIDFT_RELAXIS),
78             FE(DIDFT_ABSAXIS),
79             FE(DIDFT_PSHBUTTON),
80             FE(DIDFT_TGLBUTTON),
81             FE(DIDFT_POV),
82             FE(DIDFT_COLLECTION),
83             FE(DIDFT_NODATA),       
84             FE(DIDFT_FFACTUATOR),
85             FE(DIDFT_FFEFFECTTRIGGER),
86             FE(DIDFT_OUTPUT),
87             FE(DIDFT_VENDORDEFINED),
88             FE(DIDFT_ALIAS),
89             FE(DIDFT_OPTIONAL)
90 #undef FE
91         };
92         type = (dwFlags & 0xFF0000FF);
93         instance = ((dwFlags >> 8) & 0xFFFF);
94         DPRINTF("Type:");
95         if (type == DIDFT_ALL) {
96             DPRINTF(" DIDFT_ALL");
97         } else {
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);
102                 }
103             }
104             if (type) {
105                 DPRINTF(" (unhandled: %08x)", type);
106             }
107         }
108         DPRINTF(" / Instance: ");
109         if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
110             DPRINTF("DIDFT_ANYINSTANCE");
111         } else {
112             DPRINTF("%3d", instance);
113         }
114     }
115 }
116
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")));
124     }
125 }
126
127 void _dump_OBJECTINSTANCEA(const 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);
131     }
132 }
133
134 void _dump_OBJECTINSTANCEW(const 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));
138     }
139 }
140
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) {
143     unsigned int i;
144     static const struct {
145         const GUID *guid;
146         const char *name;
147     } guids[] = {
148 #define FE(x) { &x, #x}
149         FE(GUID_XAxis),
150         FE(GUID_YAxis),
151         FE(GUID_ZAxis),
152         FE(GUID_RxAxis),
153         FE(GUID_RyAxis),
154         FE(GUID_RzAxis),
155         FE(GUID_Slider),
156         FE(GUID_Button),
157         FE(GUID_Key),
158         FE(GUID_POV),
159         FE(GUID_Unknown),
160         FE(GUID_SysMouse),
161         FE(GUID_SysKeyboard),
162         FE(GUID_Joystick),
163         FE(GUID_ConstantForce),
164         FE(GUID_RampForce),
165         FE(GUID_Square),
166         FE(GUID_Sine),
167         FE(GUID_Triangle),
168         FE(GUID_SawtoothUp),
169         FE(GUID_SawtoothDown),
170         FE(GUID_Spring),
171         FE(GUID_Damper),
172         FE(GUID_Inertia),
173         FE(GUID_Friction),
174         FE(GUID_CustomForce)
175 #undef FE
176     };
177     if (guid == NULL)
178         return "null GUID";
179     for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
180         if (IsEqualGUID(guids[i].guid, guid)) {
181             return guids[i].name;
182         }
183     }
184     return "Unknown GUID";
185 }
186
187 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
188     unsigned int i;
189
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);
194     }
195     TRACE("  - dwObjsize: %d\n", df->dwObjSize);
196     if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
197         WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
198     }
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;
204     }
205     TRACE(")\n");
206     TRACE("  - dwDataSize: %d\n", df->dwDataSize);
207     TRACE("  - dwNumObjs: %d\n", df->dwNumObjs);
208     
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);
216     }
217 }
218
219 /* Conversion between internal data buffer and external data buffer */
220 void fill_DataFormat(void *out, const void *in, const DataFormat *df) {
221     int i;
222     const char *in_c = in;
223     char *out_c = (char *) out;
224
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);
228     } else {
229         for (i = 0; i < df->size; i++) {
230             if (df->dt[i].offset_in >= 0) {
231                 switch (df->dt[i].size) {
232                     case 1:
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);
236                         break;
237
238                     case 2:
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));
242                         break;
243
244                     case 4:
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));
248                         break;
249
250                     default:
251                         memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
252                         break;
253                 }
254             } else {
255                 switch (df->dt[i].size) {
256                     case 1:
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;
260                         break;
261                         
262                     case 2:
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;
266                         break;
267                         
268                     case 4:
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;
272                         break;
273                         
274                     default:
275                         memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
276                         break;
277                 }
278             }
279         }
280     }
281 }
282
283 void release_DataFormat(DataFormat * format)
284 {
285     TRACE("Deleting DataFormat: %p\n", format);
286
287     HeapFree(GetProcessHeap(), 0, format->dt);
288     format->dt = NULL;
289     HeapFree(GetProcessHeap(), 0, format->offsets);
290     format->offsets = NULL;
291     HeapFree(GetProcessHeap(), 0, format->user_df);
292     format->user_df = NULL;
293 }
294
295 inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
296 {
297     if (idx < 0 || idx >= df->dwNumObjs) return NULL;
298     return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
299 }
300
301 HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
302 {
303     DataTransform *dt;
304     unsigned int i, j;
305     int same = 1;
306     int *done;
307     int index = 0;
308     DWORD next = 0;
309
310     if (!format->wine_df) return DIERR_INVALIDPARAM;
311     done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
312     dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
313     if (!dt || !done) goto failed;
314
315     if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
316         goto failed;
317
318     if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
319         goto failed;
320     memcpy(format->user_df, asked_format, asked_format->dwSize);
321
322     TRACE("Creating DataTransform :\n");
323     
324     for (i = 0; i < format->wine_df->dwNumObjs; i++)
325     {
326         format->offsets[i] = -1;
327
328         for (j = 0; j < asked_format->dwNumObjs; j++) {
329             if (done[j] == 1)
330                 continue;
331             
332             if (/* Check if the application either requests any GUID and if not, it if matches
333                  * the GUID of the Wine object.
334                  */
335                 ((asked_format->rgodf[j].pguid == NULL) ||
336                  (format->wine_df->rgodf[i].pguid == NULL) ||
337                  (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
338                 &&
339                 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
340                   * instance id.
341                   */
342                  ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
343                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
344                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
345                 &&
346                 ( /* Then if the asked type matches the one Wine provides */
347                  DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
348             {
349                 done[j] = 1;
350                 
351                 TRACE("Matching :\n");
352                 TRACE("   - Asked (%d) :\n", j);
353                 TRACE("       * GUID: %s ('%s')\n",
354                       debugstr_guid(asked_format->rgodf[j].pguid),
355                       _dump_dinput_GUID(asked_format->rgodf[j].pguid));
356                 TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
357                 TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
358                 TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
359                 
360                 TRACE("   - Wine  (%d) :\n", i);
361                 TRACE("       * GUID: %s ('%s')\n",
362                       debugstr_guid(format->wine_df->rgodf[i].pguid),
363                       _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
364                 TRACE("       * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
365                 TRACE("       * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
366                 TRACE("         "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
367                 
368                 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
369                     dt[index].size = sizeof(BYTE);
370                 else
371                     dt[index].size = sizeof(DWORD);
372                 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
373                 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
374                 format->offsets[i]   = asked_format->rgodf[j].dwOfs;
375                 dt[index].value = 0;
376                 next = next + dt[index].size;
377                 
378                 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
379                     same = 0;
380                 
381                 index++;
382                 break;
383             }
384         }
385         
386         if (j == asked_format->dwNumObjs)
387             same = 0;
388     }
389     
390     TRACE("Setting to default value :\n");
391     for (j = 0; j < asked_format->dwNumObjs; j++) {
392         if (done[j] == 0) {
393             TRACE("   - Asked (%d) :\n", j);
394             TRACE("       * GUID: %s ('%s')\n",
395                   debugstr_guid(asked_format->rgodf[j].pguid),
396                   _dump_dinput_GUID(asked_format->rgodf[j].pguid));
397             TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
398             TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
399             TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
400             
401             if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
402                 dt[index].size = sizeof(BYTE);
403             else
404                 dt[index].size = sizeof(DWORD);
405             dt[index].offset_in  = -1;
406             dt[index].offset_out = asked_format->rgodf[j].dwOfs;
407             dt[index].value = 0;
408             index++;
409             
410             same = 0;
411         }
412     }
413     
414     format->internal_format_size = format->wine_df->dwDataSize;
415     format->size = index;
416     if (same) {
417         HeapFree(GetProcessHeap(), 0, dt);
418         dt = NULL;
419     }
420     format->dt = dt;
421
422     HeapFree(GetProcessHeap(), 0, done);
423
424     return DI_OK;
425
426 failed:
427     HeapFree(GetProcessHeap(), 0, done);
428     HeapFree(GetProcessHeap(), 0, dt);
429     format->dt = NULL;
430     HeapFree(GetProcessHeap(), 0, format->offsets);
431     format->offsets = NULL;
432     HeapFree(GetProcessHeap(), 0, format->user_df);
433     format->user_df = NULL;
434
435     return DIERR_OUTOFMEMORY;
436 }
437
438 /* find an object by it's offset in a data format */
439 static int offset_to_object(const DataFormat *df, int offset)
440 {
441     int i;
442
443     if (!df->offsets) return -1;
444
445     for (i = 0; i < df->wine_df->dwNumObjs; i++)
446         if (df->offsets[i] == offset) return i;
447
448     return -1;
449 }
450
451 int id_to_object(LPCDIDATAFORMAT df, int id)
452 {
453     int i;
454
455     id &= 0x00ffffff;
456     for (i = 0; i < df->dwNumObjs; i++)
457         if ((dataformat_to_odf(df, i)->dwType & 0x00ffffff) == id)
458             return i;
459
460     return -1;
461 }
462
463 int id_to_offset(const DataFormat *df, int id)
464 {
465     int obj = id_to_object(df->wine_df, id);
466
467     return obj >= 0 && df->offsets ? df->offsets[obj] : -1;
468 }
469
470 int find_property(const DataFormat *df, LPCDIPROPHEADER ph)
471 {
472     switch (ph->dwHow)
473     {
474         case DIPH_BYID:     return id_to_object(df->wine_df, ph->dwObj);
475         case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
476     }
477     FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
478
479     return -1;
480 }
481
482
483 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
484     DIDEVICEOBJECTINSTANCEW ddtmp;
485     device_enumobjects_AtoWcb_data* data;
486
487     data = (device_enumobjects_AtoWcb_data*) lpvRef;
488     
489     memset(&ddtmp, 0, sizeof(ddtmp));
490     
491     ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
492     ddtmp.guidType     = lpddi->guidType;
493     ddtmp.dwOfs        = lpddi->dwOfs;
494     ddtmp.dwType       = lpddi->dwType;
495     ddtmp.dwFlags      = lpddi->dwFlags;
496     MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
497     
498     if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
499         /**
500          * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
501          *  force feedback and other newer datas aren't available
502          */
503         ddtmp.dwFFMaxForce        = lpddi->dwFFMaxForce;
504         ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
505         ddtmp.wCollectionNumber   = lpddi->wCollectionNumber;
506         ddtmp.wDesignatorIndex    = lpddi->wDesignatorIndex;
507         ddtmp.wUsagePage          = lpddi->wUsagePage;
508         ddtmp.wUsage              = lpddi->wUsage;
509         ddtmp.dwDimension         = lpddi->dwDimension;
510         ddtmp.wExponent           = lpddi->wExponent;
511         ddtmp.wReserved           = lpddi->wReserved;
512     }
513     return data->lpCallBack(&ddtmp, data->lpvRef);
514 }
515
516 /******************************************************************************
517  *      queue_event - add new event to the ring queue
518  */
519
520 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
521 {
522     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
523     int next_pos;
524
525     /* Event is being set regardless of the queue state */
526     if (This->hEvent) SetEvent(This->hEvent);
527
528     if (!This->queue_len || This->overflow || ofs < 0) return;
529
530     next_pos = (This->queue_head + 1) % This->queue_len;
531     if (next_pos == This->queue_tail)
532     {
533         TRACE(" queue overflowed\n");
534         This->overflow = TRUE;
535         return;
536     }
537
538     TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
539           data, ofs, This->queue_head, This->queue_len);
540
541     This->data_queue[This->queue_head].dwOfs       = ofs;
542     This->data_queue[This->queue_head].dwData      = data;
543     This->data_queue[This->queue_head].dwTimeStamp = time;
544     This->data_queue[This->queue_head].dwSequence  = seq;
545     This->queue_head = next_pos;
546     /* Send event if asked */
547 }
548
549 /******************************************************************************
550  *      Acquire
551  */
552
553 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
554 {
555     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
556     HRESULT res;
557
558     if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
559     if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
560         return DIERR_OTHERAPPHASPRIO;
561
562     EnterCriticalSection(&This->crit);
563     res = This->acquired ? S_FALSE : DI_OK;
564     This->acquired = 1;
565     if (res == DI_OK)
566     {
567         This->queue_head = This->queue_tail = This->overflow = 0;
568         check_dinput_hooks(iface);
569     }
570     LeaveCriticalSection(&This->crit);
571
572     return res;
573 }
574
575 /******************************************************************************
576  *      Unacquire
577  */
578
579 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
580 {
581     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
582     HRESULT res;
583
584     EnterCriticalSection(&This->crit);
585     res = !This->acquired ? DI_NOEFFECT : DI_OK;
586     This->acquired = 0;
587     if (res == DI_OK)
588         check_dinput_hooks(iface);
589     LeaveCriticalSection(&This->crit);
590
591     return res;
592 }
593
594 /******************************************************************************
595  *      IDirectInputDeviceA
596  */
597
598 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
599         LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
600 {
601     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
602     HRESULT res = DI_OK;
603
604     if (!df) return E_POINTER;
605     TRACE("(%p) %p\n", This, df);
606     _dump_DIDATAFORMAT(df);
607
608     if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
609     if (This->acquired) return DIERR_ACQUIRED;
610
611     EnterCriticalSection(&This->crit);
612
613     release_DataFormat(&This->data_format);
614     res = create_DataFormat(df, &This->data_format);
615
616     LeaveCriticalSection(&This->crit);
617     return res;
618 }
619
620 /******************************************************************************
621   *     SetCooperativeLevel
622   *
623   *  Set cooperative level and the source window for the events.
624   */
625 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
626         LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
627 {
628     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
629
630     TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
631     TRACE(" cooperative level : ");
632     _dump_cooperativelevel_DI(dwflags);
633
634     if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
635         (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
636         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
637         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
638         return DIERR_INVALIDPARAM;
639
640     if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
641         hwnd = GetDesktopWindow();
642
643     if (!hwnd) return E_HANDLE;
644
645     /* For security reasons native does not allow exclusive background level
646        for mouse and keyboard only */
647     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
648         (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
649          IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
650         return DIERR_UNSUPPORTED;
651
652     /* Store the window which asks for the mouse */
653     EnterCriticalSection(&This->crit);
654     This->win = hwnd;
655     This->dwCoopLevel = dwflags;
656     LeaveCriticalSection(&This->crit);
657
658     return DI_OK;
659 }
660
661 /******************************************************************************
662   *     SetEventNotification : specifies event to be sent on state change
663   */
664 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
665         LPDIRECTINPUTDEVICE8A iface, HANDLE event)
666 {
667     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
668
669     TRACE("(%p) %p\n", This, event);
670
671     EnterCriticalSection(&This->crit);
672     This->hEvent = event;
673     LeaveCriticalSection(&This->crit);
674     return DI_OK;
675 }
676
677 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
678 {
679     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
680     ULONG ref;
681
682     ref = InterlockedDecrement(&(This->ref));
683     if (ref) return ref;
684
685     IDirectInputDevice_Unacquire(iface);
686     /* Reset the FF state, free all effects, etc */
687     IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
688
689     HeapFree(GetProcessHeap(), 0, This->data_queue);
690
691     /* Free data format */
692     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
693     HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
694     release_DataFormat(&This->data_format);
695
696     EnterCriticalSection( &This->dinput->crit );
697     list_remove( &This->entry );
698     LeaveCriticalSection( &This->dinput->crit );
699
700     IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
701     This->crit.DebugInfo->Spare[0] = 0;
702     DeleteCriticalSection(&This->crit);
703
704     HeapFree(GetProcessHeap(), 0, This);
705
706     return DI_OK;
707 }
708
709 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
710         LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
711 )
712 {
713     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
714     
715     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
716     if (IsEqualGUID(&IID_IUnknown,riid)) {
717         IDirectInputDevice2_AddRef(iface);
718         *ppobj = This;
719         return DI_OK;
720     }
721     if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
722         IDirectInputDevice2_AddRef(iface);
723         *ppobj = This;
724         return DI_OK;
725     }
726     if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
727         IDirectInputDevice2_AddRef(iface);
728         *ppobj = This;
729         return DI_OK;
730     }
731     if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
732         IDirectInputDevice7_AddRef(iface);
733         *ppobj = This;
734         return DI_OK;
735     }
736     if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
737         IDirectInputDevice8_AddRef(iface);
738         *ppobj = This;
739         return DI_OK;
740     }
741     TRACE("Unsupported interface !\n");
742     return E_FAIL;
743 }
744
745 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
746         LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
747 )
748 {
749     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
750     
751     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
752     if (IsEqualGUID(&IID_IUnknown,riid)) {
753         IDirectInputDevice2_AddRef(iface);
754         *ppobj = This;
755         return DI_OK;
756     }
757     if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
758         IDirectInputDevice2_AddRef(iface);
759         *ppobj = This;
760         return DI_OK;
761     }
762     if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
763         IDirectInputDevice2_AddRef(iface);
764         *ppobj = This;
765         return DI_OK;
766     }
767     if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
768         IDirectInputDevice7_AddRef(iface);
769         *ppobj = This;
770         return DI_OK;
771     }
772     if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
773         IDirectInputDevice8_AddRef(iface);
774         *ppobj = This;
775         return DI_OK;
776     }
777     TRACE("Unsupported interface !\n");
778     return E_FAIL;
779 }
780
781 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
782         LPDIRECTINPUTDEVICE8A iface)
783 {
784     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
785     return InterlockedIncrement(&(This->ref));
786 }
787
788 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface,
789         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags)
790 {
791     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
792     DIDEVICEOBJECTINSTANCEA ddoi;
793     int i;
794
795     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
796     TRACE("  - flags = ");
797     _dump_EnumObjects_flags(dwFlags);
798     TRACE("\n");
799
800     /* Only the fields till dwFFMaxForce are relevant */
801     memset(&ddoi, 0, sizeof(ddoi));
802     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
803
804     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
805     {
806         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
807
808         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
809         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
810             continue;
811
812         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
813     }
814
815     return DI_OK;
816 }
817
818 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
819         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags)
820 {
821     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
822     DIDEVICEOBJECTINSTANCEW ddoi;
823     int i;
824
825     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
826     TRACE("  - flags = ");
827     _dump_EnumObjects_flags(dwFlags);
828     TRACE("\n");
829
830     /* Only the fields till dwFFMaxForce are relevant */
831     memset(&ddoi, 0, sizeof(ddoi));
832     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, dwFFMaxForce);
833
834     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
835     {
836         LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
837
838         if (dwFlags != DIDFT_ALL && !(dwFlags & DIEFT_GETTYPE(odf->dwType))) continue;
839         if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK)
840             continue;
841
842         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
843     }
844
845     return DI_OK;
846 }
847
848 /******************************************************************************
849  *      GetProperty
850  */
851
852 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
853         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
854 {
855     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
856
857     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
858     _dump_DIPROPHEADER(pdiph);
859
860     if (HIWORD(rguid)) return DI_OK;
861
862     switch (LOWORD(rguid))
863     {
864         case (DWORD) DIPROP_BUFFERSIZE:
865         {
866             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
867
868             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
869
870             pd->dwData = This->queue_len;
871             TRACE("buffersize = %d\n", pd->dwData);
872             break;
873         }
874         default:
875             WARN("Unknown property %s\n", debugstr_guid(rguid));
876             break;
877     }
878
879     return DI_OK;
880 }
881
882 /******************************************************************************
883  *      SetProperty
884  */
885
886 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
887         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
888 {
889     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
890
891     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
892     _dump_DIPROPHEADER(pdiph);
893
894     if (HIWORD(rguid)) return DI_OK;
895
896     switch (LOWORD(rguid))
897     {
898         case (DWORD) DIPROP_AXISMODE:
899         {
900             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
901
902             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
903             if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
904             if (This->acquired) return DIERR_ACQUIRED;
905             if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
906             if (!This->data_format.user_df) return DI_OK;
907
908             TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
909                                                                         "relative");
910
911             EnterCriticalSection(&This->crit);
912             This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
913             This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
914                                                   DIDF_ABSAXIS : DIDF_RELAXIS;
915             LeaveCriticalSection(&This->crit);
916             break;
917         }
918         case (DWORD) DIPROP_BUFFERSIZE:
919         {
920             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
921
922             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
923             if (This->acquired) return DIERR_ACQUIRED;
924
925             TRACE("buffersize = %d\n", pd->dwData);
926
927             EnterCriticalSection(&This->crit);
928             HeapFree(GetProcessHeap(), 0, This->data_queue);
929
930             This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
931                                 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
932             This->queue_head = This->queue_tail = This->overflow = 0;
933             This->queue_len  = pd->dwData;
934
935             LeaveCriticalSection(&This->crit);
936             break;
937         }
938         default:
939             WARN("Unknown property %s\n", debugstr_guid(rguid));
940             return DIERR_UNSUPPORTED;
941     }
942
943     return DI_OK;
944 }
945
946 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
947         LPDIRECTINPUTDEVICE8A iface,
948         LPDIDEVICEOBJECTINSTANCEA pdidoi,
949         DWORD dwObj,
950         DWORD dwHow)
951 {
952     DIDEVICEOBJECTINSTANCEW didoiW;
953     HRESULT res;
954
955     if (!pdidoi ||
956         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA) &&
957          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A)))
958         return DIERR_INVALIDPARAM;
959
960     didoiW.dwSize = sizeof(didoiW);
961     res = IDirectInputDevice2WImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
962     if (res == DI_OK)
963     {
964         DWORD dwSize = pdidoi->dwSize;
965
966         memset(pdidoi, 0, pdidoi->dwSize);
967         pdidoi->dwSize   = dwSize;
968         pdidoi->guidType = didoiW.guidType;
969         pdidoi->dwOfs    = didoiW.dwOfs;
970         pdidoi->dwType   = didoiW.dwType;
971         pdidoi->dwFlags  = didoiW.dwFlags;
972     }
973
974     return res;
975 }
976
977 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
978         LPDIRECTINPUTDEVICE8W iface,
979         LPDIDEVICEOBJECTINSTANCEW pdidoi,
980         DWORD dwObj,
981         DWORD dwHow)
982 {
983     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
984     DWORD dwSize;
985     LPDIOBJECTDATAFORMAT odf;
986     int idx = -1;
987
988     TRACE("(%p) %d(0x%08x) -> %p\n", This, dwHow, dwObj, pdidoi);
989
990     if (!pdidoi ||
991         (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW) &&
992          pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W)))
993         return DIERR_INVALIDPARAM;
994
995     switch (dwHow)
996     {
997     case DIPH_BYOFFSET:
998         if (!This->data_format.offsets) break;
999         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1000             if (This->data_format.offsets[idx] == dwObj) break;
1001         break;
1002     case DIPH_BYID:
1003         dwObj &= 0x00ffffff;
1004         for (idx = This->data_format.wine_df->dwNumObjs - 1; idx >= 0; idx--)
1005             if ((dataformat_to_odf(This->data_format.wine_df, idx)->dwType & 0x00ffffff) == dwObj)
1006                 break;
1007         break;
1008
1009     case DIPH_BYUSAGE:
1010         FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1011         break;
1012     default:
1013         WARN("invalid parameter: dwHow = %08x\n", dwHow);
1014         return DIERR_INVALIDPARAM;
1015     }
1016     if (idx < 0) return DIERR_OBJECTNOTFOUND;
1017
1018     odf = dataformat_to_odf(This->data_format.wine_df, idx);
1019     dwSize = pdidoi->dwSize; /* save due to memset below */
1020     memset(pdidoi, 0, pdidoi->dwSize);
1021     pdidoi->dwSize   = dwSize;
1022     if (odf->pguid) pdidoi->guidType = *odf->pguid;
1023     pdidoi->dwOfs    = This->data_format.offsets ? This->data_format.offsets[idx] : odf->dwOfs;
1024     pdidoi->dwType   = odf->dwType;
1025     pdidoi->dwFlags  = odf->dwFlags;
1026
1027     return DI_OK;
1028 }
1029
1030 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
1031         LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
1032         LPDWORD entries, DWORD flags)
1033 {
1034     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1035     HRESULT ret = DI_OK;
1036     int len;
1037
1038     TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
1039           This, dod, entries, entries ? *entries : 0, dodsize, flags);
1040
1041     if (!This->acquired)
1042         return DIERR_NOTACQUIRED;
1043     if (!This->queue_len)
1044         return DIERR_NOTBUFFERED;
1045     if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1046         return DIERR_INVALIDPARAM;
1047
1048     IDirectInputDevice2_Poll(iface);
1049     EnterCriticalSection(&This->crit);
1050
1051     len = This->queue_head - This->queue_tail;
1052     if (len < 0) len += This->queue_len;
1053
1054     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1055
1056     if (dod)
1057     {
1058         int i;
1059         for (i = 0; i < len; i++)
1060         {
1061             int n = (This->queue_tail + i) % This->queue_len;
1062             memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1063         }
1064     }
1065     *entries = len;
1066
1067     if (This->overflow)
1068         ret = DI_BUFFEROVERFLOW;
1069
1070     if (!(flags & DIGDD_PEEK))
1071     {
1072         /* Advance reading position */
1073         This->queue_tail = (This->queue_tail + len) % This->queue_len;
1074         This->overflow = FALSE;
1075     }
1076
1077     LeaveCriticalSection(&This->crit);
1078
1079     TRACE("Returning %d events queued\n", *entries);
1080     return ret;
1081 }
1082
1083 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1084         LPDIRECTINPUTDEVICE8A iface,
1085         LPDIDEVICEINSTANCEA pdidi)
1086 {
1087     FIXME("(this=%p,%p): stub!\n",
1088           iface, pdidi);
1089     
1090     return DI_OK;
1091 }
1092
1093 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1094         LPDIRECTINPUTDEVICE8W iface,
1095         LPDIDEVICEINSTANCEW pdidi)
1096 {
1097     FIXME("(this=%p,%p): stub!\n",
1098           iface, pdidi);
1099     
1100     return DI_OK;
1101 }
1102
1103 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1104         LPDIRECTINPUTDEVICE8A iface,
1105         HWND hwndOwner,
1106         DWORD dwFlags)
1107 {
1108     FIXME("(this=%p,%p,0x%08x): stub!\n",
1109           iface, hwndOwner, dwFlags);
1110
1111     return DI_OK;
1112 }
1113
1114 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1115         LPDIRECTINPUTDEVICE8A iface,
1116         HINSTANCE hinst,
1117         DWORD dwVersion,
1118         REFGUID rguid)
1119 {
1120     FIXME("(this=%p,%p,%d,%s): stub!\n",
1121           iface, hinst, dwVersion, debugstr_guid(rguid));
1122     return DI_OK;
1123 }
1124
1125 /******************************************************************************
1126  *      IDirectInputDevice2A
1127  */
1128
1129 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1130         LPDIRECTINPUTDEVICE8A iface,
1131         REFGUID rguid,
1132         LPCDIEFFECT lpeff,
1133         LPDIRECTINPUTEFFECT *ppdef,
1134         LPUNKNOWN pUnkOuter)
1135 {
1136     FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1137           iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1138     return DI_OK;
1139 }
1140
1141 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1142         LPDIRECTINPUTDEVICE8A iface,
1143         LPDIENUMEFFECTSCALLBACKA lpCallback,
1144         LPVOID lpvRef,
1145         DWORD dwFlags)
1146 {
1147     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1148           iface, lpCallback, lpvRef, dwFlags);
1149     
1150     return DI_OK;
1151 }
1152
1153 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1154         LPDIRECTINPUTDEVICE8W iface,
1155         LPDIENUMEFFECTSCALLBACKW lpCallback,
1156         LPVOID lpvRef,
1157         DWORD dwFlags)
1158 {
1159     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1160           iface, lpCallback, lpvRef, dwFlags);
1161     
1162     return DI_OK;
1163 }
1164
1165 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1166         LPDIRECTINPUTDEVICE8A iface,
1167         LPDIEFFECTINFOA lpdei,
1168         REFGUID rguid)
1169 {
1170     FIXME("(this=%p,%p,%s): stub!\n",
1171           iface, lpdei, debugstr_guid(rguid));
1172     return DI_OK;
1173 }
1174
1175 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1176         LPDIRECTINPUTDEVICE8W iface,
1177         LPDIEFFECTINFOW lpdei,
1178         REFGUID rguid)
1179 {
1180     FIXME("(this=%p,%p,%s): stub!\n",
1181           iface, lpdei, debugstr_guid(rguid));
1182     return DI_OK;
1183 }
1184
1185 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1186         LPDIRECTINPUTDEVICE8A iface,
1187         LPDWORD pdwOut)
1188 {
1189     FIXME("(this=%p,%p): stub!\n",
1190           iface, pdwOut);
1191     return DI_OK;
1192 }
1193
1194 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1195         LPDIRECTINPUTDEVICE8A iface,
1196         DWORD dwFlags)
1197 {
1198     TRACE("(%p) 0x%08x:\n", iface, dwFlags);
1199     return DI_NOEFFECT;
1200 }
1201
1202 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1203         LPDIRECTINPUTDEVICE8A iface,
1204         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1205         LPVOID lpvRef,
1206         DWORD dwFlags)
1207 {
1208     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1209           iface, lpCallback, lpvRef, dwFlags);
1210     return DI_OK;
1211 }
1212
1213 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1214         LPDIRECTINPUTDEVICE8A iface,
1215         LPDIEFFESCAPE lpDIEEsc)
1216 {
1217     FIXME("(this=%p,%p): stub!\n",
1218           iface, lpDIEEsc);
1219     return DI_OK;
1220 }
1221
1222 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1223         LPDIRECTINPUTDEVICE8A iface)
1224 {
1225     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1226
1227     if (!This->acquired) return DIERR_NOTACQUIRED;
1228     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1229     return DI_NOEFFECT;
1230 }
1231
1232 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1233         LPDIRECTINPUTDEVICE8A iface,
1234         DWORD cbObjectData,
1235         LPCDIDEVICEOBJECTDATA rgdod,
1236         LPDWORD pdwInOut,
1237         DWORD dwFlags)
1238 {
1239     FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1240           iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1241     
1242     return DI_OK;
1243 }
1244
1245 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1246                                                           LPCSTR lpszFileName,
1247                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1248                                                           LPVOID pvRef,
1249                                                           DWORD dwFlags)
1250 {
1251     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1252     
1253     return DI_OK;
1254 }
1255
1256 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1257                                                           LPCWSTR lpszFileName,
1258                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1259                                                           LPVOID pvRef,
1260                                                           DWORD dwFlags)
1261 {
1262     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1263     
1264     return DI_OK;
1265 }
1266
1267 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1268                                                           LPCSTR lpszFileName,
1269                                                           DWORD dwEntries,
1270                                                           LPDIFILEEFFECT rgDiFileEft,
1271                                                           DWORD dwFlags)
1272 {
1273     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1274     
1275     return DI_OK;
1276 }
1277
1278 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1279                                                           LPCWSTR lpszFileName,
1280                                                           DWORD dwEntries,
1281                                                           LPDIFILEEFFECT rgDiFileEft,
1282                                                           DWORD dwFlags)
1283 {
1284     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1285     
1286     return DI_OK;
1287 }
1288
1289 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1290                                                        LPDIACTIONFORMATA lpdiaf,
1291                                                        LPCSTR lpszUserName,
1292                                                        DWORD dwFlags)
1293 {
1294     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1295     
1296     return DI_OK;
1297 }
1298
1299 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1300                                                        LPDIACTIONFORMATW lpdiaf,
1301                                                        LPCWSTR lpszUserName,
1302                                                        DWORD dwFlags)
1303 {
1304     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1305   
1306     return DI_OK;
1307 }
1308
1309 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1310                                                      LPDIACTIONFORMATA lpdiaf,
1311                                                      LPCSTR lpszUserName,
1312                                                      DWORD dwFlags)
1313 {
1314     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1315     
1316     return DI_OK;
1317 }
1318
1319 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1320                                                      LPDIACTIONFORMATW lpdiaf,
1321                                                      LPCWSTR lpszUserName,
1322                                                      DWORD dwFlags)
1323 {
1324     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1325     
1326     return DI_OK;
1327 }
1328
1329 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1330                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1331 {
1332     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1333     
1334     return DI_OK;
1335 }
1336
1337 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1338                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1339 {
1340     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1341     
1342     return DI_OK;
1343 }