dinput: Implement EnumOjects[A|W] in the base device class.
[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(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(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, 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     if (format->user_df)
292         HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
293     HeapFree(GetProcessHeap(), 0, format->user_df);
294     format->user_df = NULL;
295 }
296
297 /* Make all instances sequential */
298 static void calculate_ids(LPDIDATAFORMAT df)
299 {
300     int i, axis = 0, pov = 0, button = 0;
301     int axis_base, pov_base, button_base;
302     DWORD type;
303
304     /* Make two passes over the format. The first counts the number
305      * for each type and the second sets the id */
306     for (i = 0; i < df->dwNumObjs; i++)
307     {
308         type = DIDFT_GETTYPE(df->rgodf[i].dwType);
309         if      (type & DIDFT_AXIS)   axis++;
310         else if (type & DIDFT_POV)    pov++;
311         else if (type & DIDFT_BUTTON) button++;
312     }
313
314     axis_base   = 0;
315     pov_base    = axis_base + axis;
316     button_base = pov_base + pov;
317     axis = pov = button = 0;
318
319     for (i = 0; i < df->dwNumObjs; i++)
320     {
321         type = DIDFT_GETTYPE(df->rgodf[i].dwType);
322         if (type & DIDFT_AXIS)
323         {
324             type |= DIDFT_MAKEINSTANCE(axis_base + axis++);
325             TRACE("axis type = 0x%08x\n", type);
326         } else if (type & DIDFT_POV)
327         {
328             type |= DIDFT_MAKEINSTANCE(pov_base + pov++);
329             TRACE("POV type = 0x%08x\n", type);
330         } else if (type & DIDFT_BUTTON)
331         {
332             type |= DIDFT_MAKEINSTANCE(button_base + button++);
333             TRACE("button type = 0x%08x\n", type);
334         }
335         df->rgodf[i].dwType = type;
336     }
337 }
338
339 HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format)
340 {
341     DataTransform *dt;
342     unsigned int i, j;
343     int same = 1;
344     int *done;
345     int index = 0;
346     DWORD next = 0;
347
348     if (!format->wine_df) return DIERR_INVALIDPARAM;
349     done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
350     dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
351     if (!dt || !done) goto failed;
352
353     if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
354         goto failed;
355
356     if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
357         goto failed;
358     memcpy(format->user_df, asked_format, asked_format->dwSize);
359
360     if (!(format->user_df->rgodf = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs*asked_format->dwObjSize)))
361         goto failed;
362     memcpy(format->user_df->rgodf, asked_format->rgodf, asked_format->dwNumObjs*asked_format->dwObjSize);
363
364     TRACE("Creating DataTransform :\n");
365     
366     for (i = 0; i < format->wine_df->dwNumObjs; i++)
367     {
368         format->offsets[i] = -1;
369
370         for (j = 0; j < asked_format->dwNumObjs; j++) {
371             if (done[j] == 1)
372                 continue;
373             
374             if (/* Check if the application either requests any GUID and if not, it if matches
375                  * the GUID of the Wine object.
376                  */
377                 ((asked_format->rgodf[j].pguid == NULL) ||
378                  (format->wine_df->rgodf[i].pguid == NULL) ||
379                  (IsEqualGUID(format->wine_df->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
380                 &&
381                 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
382                   * instance id.
383                   */
384                  ((asked_format->rgodf[j].dwType & DIDFT_INSTANCEMASK) == DIDFT_ANYINSTANCE) ||
385                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
386                  (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(format->wine_df->rgodf[i].dwType)))
387                 &&
388                 ( /* Then if the asked type matches the one Wine provides */
389                  DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & format->wine_df->rgodf[i].dwType))
390             {
391                 done[j] = 1;
392                 
393                 TRACE("Matching :\n");
394                 TRACE("   - Asked (%d) :\n", j);
395                 TRACE("       * GUID: %s ('%s')\n",
396                       debugstr_guid(asked_format->rgodf[j].pguid),
397                       _dump_dinput_GUID(asked_format->rgodf[j].pguid));
398                 TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
399                 TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
400                 TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
401                 
402                 TRACE("   - Wine  (%d) :\n", i);
403                 TRACE("       * GUID: %s ('%s')\n",
404                       debugstr_guid(format->wine_df->rgodf[i].pguid),
405                       _dump_dinput_GUID(format->wine_df->rgodf[i].pguid));
406                 TRACE("       * Offset: %3d\n", format->wine_df->rgodf[i].dwOfs);
407                 TRACE("       * dwType: %08x\n", format->wine_df->rgodf[i].dwType);
408                 TRACE("         "); _dump_EnumObjects_flags(format->wine_df->rgodf[i].dwType); TRACE("\n");
409                 
410                 if (format->wine_df->rgodf[i].dwType & DIDFT_BUTTON)
411                     dt[index].size = sizeof(BYTE);
412                 else
413                     dt[index].size = sizeof(DWORD);
414                 dt[index].offset_in = format->wine_df->rgodf[i].dwOfs;
415                 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
416                 format->offsets[i]   = asked_format->rgodf[j].dwOfs;
417                 dt[index].value = 0;
418                 next = next + dt[index].size;
419                 
420                 if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out)
421                     same = 0;
422                 
423                 index++;
424                 break;
425             }
426         }
427         
428         if (j == asked_format->dwNumObjs)
429             same = 0;
430     }
431     
432     TRACE("Setting to default value :\n");
433     for (j = 0; j < asked_format->dwNumObjs; j++) {
434         if (done[j] == 0) {
435             TRACE("   - Asked (%d) :\n", j);
436             TRACE("       * GUID: %s ('%s')\n",
437                   debugstr_guid(asked_format->rgodf[j].pguid),
438                   _dump_dinput_GUID(asked_format->rgodf[j].pguid));
439             TRACE("       * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
440             TRACE("       * dwType: %08x\n", asked_format->rgodf[j].dwType);
441             TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
442             
443             if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
444                 dt[index].size = sizeof(BYTE);
445             else
446                 dt[index].size = sizeof(DWORD);
447             dt[index].offset_in  = -1;
448             dt[index].offset_out = asked_format->rgodf[j].dwOfs;
449             dt[index].value = 0;
450             index++;
451             
452             same = 0;
453         }
454     }
455     
456     format->internal_format_size = format->wine_df->dwDataSize;
457     format->size = index;
458     if (same) {
459         HeapFree(GetProcessHeap(), 0, dt);
460         dt = NULL;
461     }
462     format->dt = dt;
463
464     HeapFree(GetProcessHeap(), 0, done);
465
466     /* Last step - reset all instances of the new format */
467     calculate_ids(format->user_df);
468     return DI_OK;
469
470 failed:
471     HeapFree(GetProcessHeap(), 0, done);
472     HeapFree(GetProcessHeap(), 0, dt);
473     format->dt = NULL;
474     HeapFree(GetProcessHeap(), 0, format->offsets);
475     format->offsets = NULL;
476     if (format->user_df)
477         HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
478     HeapFree(GetProcessHeap(), 0, format->user_df);
479     format->user_df = NULL;
480
481     return DIERR_OUTOFMEMORY;
482 }
483
484 /* find an object by it's offset in a data format */
485 int offset_to_object(LPCDIDATAFORMAT df, int offset)
486 {
487     int i;
488
489     for (i = 0; i < df->dwNumObjs; i++)
490         if (df->rgodf[i].dwOfs == offset)
491             return i;
492
493     return -1;
494 }
495
496 static int id_to_object(LPCDIDATAFORMAT df, int id)
497 {
498     int i;
499
500     for (i = 0; i < df->dwNumObjs; i++)
501         if ((df->rgodf[i].dwType & 0x00ffffff) == (id & 0x00ffffff))
502             return i;
503
504     return -1;
505 }
506
507 int find_property(LPCDIDATAFORMAT df, LPCDIPROPHEADER ph)
508 {
509     switch (ph->dwHow)
510     {
511         case DIPH_BYID:     return id_to_object(df, ph->dwObj);
512         case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
513     }
514     FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
515
516     return -1;
517 }
518
519
520 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
521     DIDEVICEOBJECTINSTANCEW ddtmp;
522     device_enumobjects_AtoWcb_data* data;
523
524     data = (device_enumobjects_AtoWcb_data*) lpvRef;
525     
526     memset(&ddtmp, 0, sizeof(ddtmp));
527     
528     ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
529     ddtmp.guidType     = lpddi->guidType;
530     ddtmp.dwOfs        = lpddi->dwOfs;
531     ddtmp.dwType       = lpddi->dwType;
532     ddtmp.dwFlags      = lpddi->dwFlags;
533     MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
534     
535     if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
536         /**
537          * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
538          *  force feedback and other newer datas aren't available
539          */
540         ddtmp.dwFFMaxForce        = lpddi->dwFFMaxForce;
541         ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
542         ddtmp.wCollectionNumber   = lpddi->wCollectionNumber;
543         ddtmp.wDesignatorIndex    = lpddi->wDesignatorIndex;
544         ddtmp.wUsagePage          = lpddi->wUsagePage;
545         ddtmp.wUsage              = lpddi->wUsage;
546         ddtmp.dwDimension         = lpddi->dwDimension;
547         ddtmp.wExponent           = lpddi->wExponent;
548         ddtmp.wReserved           = lpddi->wReserved;
549     }
550     return data->lpCallBack(&ddtmp, data->lpvRef);
551 }
552
553 /******************************************************************************
554  *      queue_event - add new event to the ring queue
555  */
556
557 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
558 {
559     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
560     int next_pos;
561
562     if (!This->queue_len || This->overflow || ofs < 0) return;
563
564     next_pos = (This->queue_head + 1) % This->queue_len;
565     if (next_pos == This->queue_tail)
566     {
567         TRACE(" queue overflowed\n");
568         This->overflow = TRUE;
569         return;
570     }
571
572     TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
573           data, ofs, This->queue_head, This->queue_len);
574
575     This->data_queue[This->queue_head].dwOfs       = ofs;
576     This->data_queue[This->queue_head].dwData      = data;
577     This->data_queue[This->queue_head].dwTimeStamp = time;
578     This->data_queue[This->queue_head].dwSequence  = seq;
579     This->queue_head = next_pos;
580 }
581
582 /******************************************************************************
583  *      Acquire
584  */
585
586 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
587 {
588     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
589     HRESULT res;
590
591     if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
592
593     EnterCriticalSection(&This->crit);
594     res = This->acquired ? S_FALSE : DI_OK;
595     This->acquired = 1;
596     if (res == DI_OK)
597         This->queue_head = This->queue_tail = This->overflow = 0;
598     LeaveCriticalSection(&This->crit);
599
600     return res;
601 }
602
603 /******************************************************************************
604  *      Unacquire
605  */
606
607 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
608 {
609     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
610     HRESULT res;
611
612     EnterCriticalSection(&This->crit);
613     res = !This->acquired ? DI_NOEFFECT : DI_OK;
614     This->acquired = 0;
615     LeaveCriticalSection(&This->crit);
616
617     return res;
618 }
619
620 /******************************************************************************
621  *      IDirectInputDeviceA
622  */
623
624 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
625         LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
626 {
627     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
628     HRESULT res = DI_OK;
629
630     if (!df) return E_POINTER;
631     TRACE("(%p) %p\n", This, df);
632     _dump_DIDATAFORMAT(df);
633
634     if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
635     if (This->acquired) return DIERR_ACQUIRED;
636
637     EnterCriticalSection(&This->crit);
638
639     release_DataFormat(&This->data_format);
640     res = create_DataFormat(df, &This->data_format);
641
642     LeaveCriticalSection(&This->crit);
643     return res;
644 }
645
646 /******************************************************************************
647   *     SetCooperativeLevel
648   *
649   *  Set cooperative level and the source window for the events.
650   */
651 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
652         LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
653 {
654     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
655
656     TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
657     TRACE(" cooperative level : ");
658     _dump_cooperativelevel_DI(dwflags);
659
660     if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
661         (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
662         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
663         (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
664         return DIERR_INVALIDPARAM;
665
666     if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
667         hwnd = GetDesktopWindow();
668
669     if (!hwnd) return E_HANDLE;
670
671     /* For security reasons native does not allow exclusive background level
672        for mouse and keyboard only */
673     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
674         (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
675          IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
676         return DIERR_UNSUPPORTED;
677
678     /* Store the window which asks for the mouse */
679     EnterCriticalSection(&This->crit);
680     This->win = hwnd;
681     This->dwCoopLevel = dwflags;
682     LeaveCriticalSection(&This->crit);
683
684     return DI_OK;
685 }
686
687 /******************************************************************************
688   *     SetEventNotification : specifies event to be sent on state change
689   */
690 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
691         LPDIRECTINPUTDEVICE8A iface, HANDLE event)
692 {
693     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
694
695     TRACE("(%p) %p\n", This, event);
696
697     EnterCriticalSection(&This->crit);
698     This->hEvent = event;
699     LeaveCriticalSection(&This->crit);
700     return DI_OK;
701 }
702
703 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
704 {
705     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
706     ULONG ref;
707
708     ref = InterlockedDecrement(&(This->ref));
709     if (ref) return ref;
710
711     DeleteCriticalSection(&This->crit);
712     HeapFree(GetProcessHeap(), 0, This->data_queue);
713     HeapFree(GetProcessHeap(), 0, This);
714
715     return DI_OK;
716 }
717
718 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
719         LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
720 )
721 {
722     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
723     
724     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
725     if (IsEqualGUID(&IID_IUnknown,riid)) {
726         IDirectInputDevice2_AddRef(iface);
727         *ppobj = This;
728         return DI_OK;
729     }
730     if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
731         IDirectInputDevice2_AddRef(iface);
732         *ppobj = This;
733         return DI_OK;
734     }
735     if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
736         IDirectInputDevice2_AddRef(iface);
737         *ppobj = This;
738         return DI_OK;
739     }
740     if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
741         IDirectInputDevice7_AddRef(iface);
742         *ppobj = This;
743         return DI_OK;
744     }
745     if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
746         IDirectInputDevice8_AddRef(iface);
747         *ppobj = This;
748         return DI_OK;
749     }
750     TRACE("Unsupported interface !\n");
751     return E_FAIL;
752 }
753
754 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
755         LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
756 )
757 {
758     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
759     
760     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
761     if (IsEqualGUID(&IID_IUnknown,riid)) {
762         IDirectInputDevice2_AddRef(iface);
763         *ppobj = This;
764         return DI_OK;
765     }
766     if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
767         IDirectInputDevice2_AddRef(iface);
768         *ppobj = This;
769         return DI_OK;
770     }
771     if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
772         IDirectInputDevice2_AddRef(iface);
773         *ppobj = This;
774         return DI_OK;
775     }
776     if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
777         IDirectInputDevice7_AddRef(iface);
778         *ppobj = This;
779         return DI_OK;
780     }
781     if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
782         IDirectInputDevice8_AddRef(iface);
783         *ppobj = This;
784         return DI_OK;
785     }
786     TRACE("Unsupported interface !\n");
787     return E_FAIL;
788 }
789
790 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
791         LPDIRECTINPUTDEVICE8A iface)
792 {
793     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
794     return InterlockedIncrement(&(This->ref));
795 }
796
797 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
798         LPDIRECTINPUTDEVICE8A iface,
799         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
800         LPVOID lpvRef,
801         DWORD dwFlags)
802 {
803     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
804     DIDEVICEOBJECTINSTANCEA ddoi;
805     int i, axis = 0, button = 0;
806
807     TRACE("(%p) %p,%p flags:%08x)\n", iface, lpCallback, lpvRef, dwFlags);
808     TRACE("  - flags = ");
809     _dump_EnumObjects_flags(dwFlags);
810     TRACE("\n");
811
812     /* Only the fields till dwFFMaxForce are relevant */
813     memset(&ddoi, 0, sizeof(ddoi));
814     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
815
816     for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++)
817     {
818         LPDIOBJECTDATAFORMAT odf;
819         DWORD type;
820
821         odf = (LPDIOBJECTDATAFORMAT)((LPBYTE)This->data_format.wine_df->rgodf +
822                                          i * This->data_format.wine_df->dwObjSize);
823         type = DIEFT_GETTYPE(odf->dwType);
824
825         if      (type & DIDFT_AXIS)   axis++;
826         else if (type & DIDFT_BUTTON) button++;
827
828         if (dwFlags != DIDFT_ALL && !(dwFlags & type)) continue;
829
830         ddoi.guidType = *odf->pguid;
831         ddoi.dwType   =  odf->dwType;
832         ddoi.dwFlags  =  odf->dwFlags;
833         ddoi.dwOfs    =  !This->data_format.offsets ? odf->dwOfs : This->data_format.offsets[i];
834
835         if      (IsEqualGUID(&ddoi.guidType, &GUID_XAxis)) strcpy(ddoi.tszName, "X-Axis");
836         else if (IsEqualGUID(&ddoi.guidType, &GUID_YAxis)) strcpy(ddoi.tszName, "Y-Axis");
837         else if (IsEqualGUID(&ddoi.guidType, &GUID_ZAxis)) strcpy(ddoi.tszName, "Z-Axis");
838         else if (type & DIDFT_AXIS)   wsprintfA(ddoi.tszName, "%d-Axis", axis - 1);
839         else if (type & DIDFT_BUTTON) wsprintfA(ddoi.tszName, "Button %d", button - 1);
840         else FIXME("no name\n");
841
842         _dump_OBJECTINSTANCEA(&ddoi);
843         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break;
844     }
845
846     return DI_OK;
847 }
848
849 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(
850         LPDIRECTINPUTDEVICE8W iface,
851         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
852         LPVOID lpvRef,
853         DWORD dwFlags)
854 {
855     device_enumobjects_AtoWcb_data data;
856
857     data.lpCallBack = lpCallback;
858     data.lpvRef = lpvRef;
859
860     return IDirectInputDevice2AImpl_EnumObjects(
861                 (LPDIRECTINPUTDEVICE8A) iface,
862                 (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW,
863                 (LPVOID) &data, dwFlags);
864 }
865
866 /******************************************************************************
867  *      GetProperty
868  */
869
870 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
871         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
872 {
873     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
874
875     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
876     _dump_DIPROPHEADER(pdiph);
877
878     if (HIWORD(rguid)) return DI_OK;
879
880     switch (LOWORD(rguid))
881     {
882         case (DWORD) DIPROP_BUFFERSIZE:
883         {
884             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
885
886             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
887
888             pd->dwData = This->queue_len;
889             TRACE("buffersize = %d\n", pd->dwData);
890             break;
891         }
892         default:
893             WARN("Unknown property %s\n", debugstr_guid(rguid));
894             break;
895     }
896
897     return DI_OK;
898 }
899
900 /******************************************************************************
901  *      SetProperty
902  */
903
904 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
905         LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
906 {
907     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
908
909     TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
910     _dump_DIPROPHEADER(pdiph);
911
912     if (HIWORD(rguid)) return DI_OK;
913
914     switch (LOWORD(rguid))
915     {
916         case (DWORD) DIPROP_AXISMODE:
917         {
918             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
919
920             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
921             if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM;
922             if (This->acquired) return DIERR_ACQUIRED;
923             if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
924             if (!This->data_format.user_df) return DI_OK;
925
926             TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" :
927                                                                         "relative");
928
929             EnterCriticalSection(&This->crit);
930             This->data_format.user_df->dwFlags &= ~DIDFT_AXIS;
931             This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ?
932                                                   DIDF_ABSAXIS : DIDF_RELAXIS;
933             LeaveCriticalSection(&This->crit);
934             break;
935         }
936         case (DWORD) DIPROP_BUFFERSIZE:
937         {
938             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
939
940             if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
941             if (This->acquired) return DIERR_ACQUIRED;
942
943             TRACE("buffersize = %d\n", pd->dwData);
944
945             EnterCriticalSection(&This->crit);
946             HeapFree(GetProcessHeap(), 0, This->data_queue);
947
948             This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
949                                 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
950             This->queue_head = This->queue_tail = This->overflow = 0;
951             This->queue_len  = pd->dwData;
952
953             LeaveCriticalSection(&This->crit);
954             break;
955         }
956         default:
957             WARN("Unknown property %s\n", debugstr_guid(rguid));
958             return DIERR_UNSUPPORTED;
959     }
960
961     return DI_OK;
962 }
963
964 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
965         LPDIRECTINPUTDEVICE8A iface,
966         LPDIDEVICEOBJECTINSTANCEA pdidoi,
967         DWORD dwObj,
968         DWORD dwHow)
969 {
970     FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
971           iface, pdidoi, dwObj, dwHow);
972     
973     return DI_OK;
974 }
975
976 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
977         LPDIRECTINPUTDEVICE8W iface,
978         LPDIDEVICEOBJECTINSTANCEW pdidoi,
979         DWORD dwObj,
980         DWORD dwHow)
981 {
982     FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
983           iface, pdidoi, dwObj, dwHow);
984     
985     return DI_OK;
986 }
987
988 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
989         LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
990         LPDWORD entries, DWORD flags)
991 {
992     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
993     HRESULT ret = DI_OK;
994     int len;
995
996     TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
997           This, dod, entries, entries ? *entries : 0, dodsize, flags);
998
999     if (!This->acquired)
1000         return DIERR_NOTACQUIRED;
1001     if (!This->queue_len)
1002         return DIERR_NOTBUFFERED;
1003     if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
1004         return DIERR_INVALIDPARAM;
1005
1006     IDirectInputDevice2_Poll(iface);
1007     EnterCriticalSection(&This->crit);
1008
1009     len = This->queue_head - This->queue_tail;
1010     if (len < 0) len += This->queue_len;
1011
1012     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
1013
1014     if (dod)
1015     {
1016         int i;
1017         for (i = 0; i < len; i++)
1018         {
1019             int n = (This->queue_tail + i) % This->queue_len;
1020             memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
1021         }
1022     }
1023     *entries = len;
1024
1025     if (This->overflow)
1026         ret = DI_BUFFEROVERFLOW;
1027
1028     if (!(flags & DIGDD_PEEK))
1029     {
1030         /* Advance reading position */
1031         This->queue_tail = (This->queue_tail + len) % This->queue_len;
1032         This->overflow = FALSE;
1033     }
1034
1035     LeaveCriticalSection(&This->crit);
1036
1037     TRACE("Returning %d events queued\n", *entries);
1038     return ret;
1039 }
1040
1041 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
1042         LPDIRECTINPUTDEVICE8A iface,
1043         LPDIDEVICEINSTANCEA pdidi)
1044 {
1045     FIXME("(this=%p,%p): stub!\n",
1046           iface, pdidi);
1047     
1048     return DI_OK;
1049 }
1050
1051 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
1052         LPDIRECTINPUTDEVICE8W iface,
1053         LPDIDEVICEINSTANCEW pdidi)
1054 {
1055     FIXME("(this=%p,%p): stub!\n",
1056           iface, pdidi);
1057     
1058     return DI_OK;
1059 }
1060
1061 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
1062         LPDIRECTINPUTDEVICE8A iface,
1063         HWND hwndOwner,
1064         DWORD dwFlags)
1065 {
1066     FIXME("(this=%p,%p,0x%08x): stub!\n",
1067           iface, hwndOwner, dwFlags);
1068
1069     return DI_OK;
1070 }
1071
1072 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
1073         LPDIRECTINPUTDEVICE8A iface,
1074         HINSTANCE hinst,
1075         DWORD dwVersion,
1076         REFGUID rguid)
1077 {
1078     FIXME("(this=%p,%p,%d,%s): stub!\n",
1079           iface, hinst, dwVersion, debugstr_guid(rguid));
1080     return DI_OK;
1081 }
1082
1083 /******************************************************************************
1084  *      IDirectInputDevice2A
1085  */
1086
1087 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
1088         LPDIRECTINPUTDEVICE8A iface,
1089         REFGUID rguid,
1090         LPCDIEFFECT lpeff,
1091         LPDIRECTINPUTEFFECT *ppdef,
1092         LPUNKNOWN pUnkOuter)
1093 {
1094     FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
1095           iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
1096     return DI_OK;
1097 }
1098
1099 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
1100         LPDIRECTINPUTDEVICE8A iface,
1101         LPDIENUMEFFECTSCALLBACKA lpCallback,
1102         LPVOID lpvRef,
1103         DWORD dwFlags)
1104 {
1105     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1106           iface, lpCallback, lpvRef, dwFlags);
1107     
1108     return DI_OK;
1109 }
1110
1111 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
1112         LPDIRECTINPUTDEVICE8W iface,
1113         LPDIENUMEFFECTSCALLBACKW lpCallback,
1114         LPVOID lpvRef,
1115         DWORD dwFlags)
1116 {
1117     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1118           iface, lpCallback, lpvRef, dwFlags);
1119     
1120     return DI_OK;
1121 }
1122
1123 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
1124         LPDIRECTINPUTDEVICE8A iface,
1125         LPDIEFFECTINFOA lpdei,
1126         REFGUID rguid)
1127 {
1128     FIXME("(this=%p,%p,%s): stub!\n",
1129           iface, lpdei, debugstr_guid(rguid));
1130     return DI_OK;
1131 }
1132
1133 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1134         LPDIRECTINPUTDEVICE8W iface,
1135         LPDIEFFECTINFOW lpdei,
1136         REFGUID rguid)
1137 {
1138     FIXME("(this=%p,%p,%s): stub!\n",
1139           iface, lpdei, debugstr_guid(rguid));
1140     return DI_OK;
1141 }
1142
1143 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1144         LPDIRECTINPUTDEVICE8A iface,
1145         LPDWORD pdwOut)
1146 {
1147     FIXME("(this=%p,%p): stub!\n",
1148           iface, pdwOut);
1149     return DI_OK;
1150 }
1151
1152 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1153         LPDIRECTINPUTDEVICE8A iface,
1154         DWORD dwFlags)
1155 {
1156     FIXME("(this=%p,0x%08x): stub!\n",
1157           iface, dwFlags);
1158     return DI_OK;
1159 }
1160
1161 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1162         LPDIRECTINPUTDEVICE8A iface,
1163         LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1164         LPVOID lpvRef,
1165         DWORD dwFlags)
1166 {
1167     FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1168           iface, lpCallback, lpvRef, dwFlags);
1169     return DI_OK;
1170 }
1171
1172 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1173         LPDIRECTINPUTDEVICE8A iface,
1174         LPDIEFFESCAPE lpDIEEsc)
1175 {
1176     FIXME("(this=%p,%p): stub!\n",
1177           iface, lpDIEEsc);
1178     return DI_OK;
1179 }
1180
1181 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1182         LPDIRECTINPUTDEVICE8A iface)
1183 {
1184     IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1185
1186     if (!This->acquired) return DIERR_NOTACQUIRED;
1187     /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1188     return DI_NOEFFECT;
1189 }
1190
1191 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1192         LPDIRECTINPUTDEVICE8A iface,
1193         DWORD cbObjectData,
1194         LPCDIDEVICEOBJECTDATA rgdod,
1195         LPDWORD pdwInOut,
1196         DWORD dwFlags)
1197 {
1198     FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1199           iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1200     
1201     return DI_OK;
1202 }
1203
1204 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1205                                                           LPCSTR lpszFileName,
1206                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1207                                                           LPVOID pvRef,
1208                                                           DWORD dwFlags)
1209 {
1210     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1211     
1212     return DI_OK;
1213 }
1214
1215 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1216                                                           LPCWSTR lpszFileName,
1217                                                           LPDIENUMEFFECTSINFILECALLBACK pec,
1218                                                           LPVOID pvRef,
1219                                                           DWORD dwFlags)
1220 {
1221     FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1222     
1223     return DI_OK;
1224 }
1225
1226 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1227                                                           LPCSTR lpszFileName,
1228                                                           DWORD dwEntries,
1229                                                           LPDIFILEEFFECT rgDiFileEft,
1230                                                           DWORD dwFlags)
1231 {
1232     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1233     
1234     return DI_OK;
1235 }
1236
1237 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1238                                                           LPCWSTR lpszFileName,
1239                                                           DWORD dwEntries,
1240                                                           LPDIFILEEFFECT rgDiFileEft,
1241                                                           DWORD dwFlags)
1242 {
1243     FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1244     
1245     return DI_OK;
1246 }
1247
1248 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1249                                                        LPDIACTIONFORMATA lpdiaf,
1250                                                        LPCSTR lpszUserName,
1251                                                        DWORD dwFlags)
1252 {
1253     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1254     
1255     return DI_OK;
1256 }
1257
1258 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1259                                                        LPDIACTIONFORMATW lpdiaf,
1260                                                        LPCWSTR lpszUserName,
1261                                                        DWORD dwFlags)
1262 {
1263     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1264   
1265     return DI_OK;
1266 }
1267
1268 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1269                                                      LPDIACTIONFORMATA lpdiaf,
1270                                                      LPCSTR lpszUserName,
1271                                                      DWORD dwFlags)
1272 {
1273     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1274     
1275     return DI_OK;
1276 }
1277
1278 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1279                                                      LPDIACTIONFORMATW lpdiaf,
1280                                                      LPCWSTR lpszUserName,
1281                                                      DWORD dwFlags)
1282 {
1283     FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1284     
1285     return DI_OK;
1286 }
1287
1288 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1289                                                      LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1290 {
1291     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1292     
1293     return DI_OK;
1294 }
1295
1296 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1297                                                      LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1298 {
1299     FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1300     
1301     return DI_OK;
1302 }